我正在尝试通过意图发送短信,我想在消息中添加正文。用户按下后send
我想返回应用程序。我已经添加了额外的内容sms_body
and exit_on_sent
。但是当我使用它们时,短信都会出现而没有正文。如果我不使用exit_on_sent
额外一切工作正常。
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.setData(Uri.parse("smsto:" + phoneNumber));
sendIntent.putExtra("sms_body", "some text");
sendIntent.putExtra("exit_on_sent", true);
context.startActivity(sendIntent);
你可以尝试使用
startActivityForResult(sendIntent, SOME_REQUEST_CODE)
但根据我的经验,大多数时候它不起作用。
我建议使用 SmsManager。
SmsManager smsMgr = SmsManager.getDefault();
if(smsMgr != null){
PendingIntent sentIntent = PendingIntent.getBroadcast(
getActivity().getApplicationContext(), 0,
new Intent(MY_ACTION_INTENT_SENT), 0);
smsMgr.sendTextMessage(phone, null, message, sentIntent, null);
}
根据您的应用程序,您可以在发送 MY_ACTION_INTENT 时(指示消息已实际发送)或在 sendTextMessage(...) 返回后立即执行其余处理。
从 API 级别 19 开始,您可能会发现一些有用的有趣功能http://developer.android.com/reference/android/provider/Telephony.html http://developer.android.com/reference/android/provider/Telephony.html
希望能帮助到你。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)