安卓:通过故意发送短信与身体和回回来。 [英] Android: sending SMS through intent with body and returning back.

查看:256
本文介绍了安卓:通过故意发送短信与身体和回回来。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过一个意图发送短信,我想身体添加到消息。用户preSS后发送我想回到应用程序。我已经添加了额外的 SMS_BODY exit_on_sent 。但是,当我使用这两个短信没有出现身体。如果我不使用 exit_on_sent 额外的一切工作正常。

 意图sendIntent =新意图(Intent.ACTION_VIEW);
    sendIntent.setData(Uri.parse(smsto:+ phoneNumber的));
    sendIntent.putExtra(SMS_BODY,一些文字);
    sendIntent.putExtra(exit_on_sent,真正的);
    context.startActivity(sendIntent);


解决方案

您可以尝试使用

  startActivityForResult(sendIntent,SOME_REQUEST_ code)

但在我的经验,它不工作的大部分时间。
我会建议,而不是使用SmsManager。

  SmsManager smsMgr = SmsManager.getDefault();
如果(smsMgr!= NULL){
  的PendingIntent sentIntent = PendingIntent.getBroadcast(
      getActivity()。getApplicationContext(),0,
      新意图(MY_ACTION_INTENT_SENT),0);
  smsMgr.sendTextMessage(电话,空,消息,sentIntent,NULL);
}

根据您的应用程序,你可以做加工静止时MY_ACTION_INTENT发送(表示该消息实际上已发送)或之后sendTextMessage(...)的回报。

从API级别19也有一些有趣的功能,你可能会发现有用的http:/ /developer.android.com/reference/android/provider/Telephony.html

希望它帮助。

I am trying to send a SMS through an intent, I want to add a body to the message. After user press send I want to return to the app. I've added extra as sms_body and exit_on_sent. But when I use them both the SMS appears without the body. If i don't use the exit_on_sent extra everything works fine.

    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);

解决方案

You could try using

startActivityForResult(sendIntent, SOME_REQUEST_CODE) 

but in my experience it doesn't works most of the time. I would recommend instead using 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);
}

Depending on your application you can do the rest of processing when MY_ACTION_INTENT is sent (indicating the message has actually been sent) or right after sendTextMessage(...) returns.

From API Level 19 there are some interesting features you may found useful http://developer.android.com/reference/android/provider/Telephony.html

Hope it helps.

这篇关于安卓:通过故意发送短信与身体和回回来。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆