很多软件都有分享的功能,不少是支持短信分享的,其实就是调用系统发送短信的Activity。代码实现非常简单:
1 |
/** |
2 |
3 |
* 发送短信 |
4 |
5 |
* @param smsBody |
6 |
7 |
*/ |
8 |
9 |
private void sendSMS(String smsBody) |
10 |
11 |
{ |
12 |
13 |
Uri smsToUri = Uri.parse( "smsto:" ); |
14 |
15 |
Intent intent = new Intent(Intent.ACTION_SENDTO, smsToUri); |
16 |
17 |
intent.putExtra( "sms_body" , smsBody); |
18 |
19 |
startActivity(intent); |
20 |
21 |
} |
如果想指定发送人,则修改如下:
1 |
/** |
2 |
3 |
* 发送短信 |
4 |
5 |
* @param smsBody |
6 |
7 |
*/ |
8 |
9 |
private void sendSMS(String smsBody) |
10 |
11 |
{ |
12 |
13 |
Uri smsToUri = Uri.parse( "smsto:10000" ); |
14 |
15 |
Intent intent = new Intent(Intent.ACTION_SENDTO, smsToUri); |
16 |
17 |
intent.putExtra( "sms_body" , smsBody); |
18 |
19 |
startActivity(intent); |
20 |
21 |
} |
看下效果图吧: