开发者

android: handover sms to default application

Please guide, in Android how can I pass my string (less开发者_如何学编程 then 160 char) to the default built-in SMS applicaion or queue, which will complete the process.

I mean, from my activity I want to call a built-in SMS application and pass my SMS string to that, then the built-in application will be responsible to rest of activity like SMS resending, etc.


To call the default sms application, with sms body and phone number :

Intent intent = new Intent( Intent.ACTION_VIEW, Uri.parse( "sms:" + phoneNumber ) );
intent.putExtra( "sms_body", smsBody );
context.startActivity( intent );

By default I mean the application chosen by the user. Actually it's better to start the default sms application than the built-in because you have to respect the user choice. If the device owner has chosen ChompSms as default SMS application, he will prefer your application launches ChompSms and not an other.


To call the default sms application, with sms body and phone number :

Uri uri = Uri.parse("smsto:123456789");   
    Intent it = new Intent(Intent.ACTION_SENDTO, uri);   
    it.putExtra("sms_body", "The Hello How R U...");   
    startActivity(it); 


Beyond Thomas' answer, you can use ACTION_SEND and createChooser() to allow the user to pick the application with which to send your message, whether that be the built-in SMS application or a third-party SMS application or email or GMail or Twidroid or whatever.

You can also use SmsManager to send the SMS yourself, but that will not pop up any built-in activity.

With luck, there is a spot in the documentation that covers Thomas's answer (elsewhere in this StackOverflow page), as that is the simplest solution to your request.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜