Android基础之批量发送短信

// 短信发送方式1
Uri smsToUri = Uri.parse("smsto:" + "12345678;123456789");
Intent intent = new Intent(Intent.ACTION_SENDTO, smsToUri);
intent.putExtra("sms_body", "短信内容");
startActivity(intent);

// 短信发送方式2
Intent smsIntent = new Intent(Intent.ACTION_VIEW);
smsIntent.setData(Uri.parse("smsto:"));
smsIntent.setType("vnd.android-dir/mms-sms");
smsIntent.putExtra("address", "12345678;123456789");
smsIntent.putExtra("sms_body", "测试");
startActivity(smsIntent);

// 长短信发送方式1
Intent sendIntent = new Intent("SENT_SMS_ACTION");
PendingIntent sendPI = PendingIntent.getBroadcast(getApplicationContext(), 0, sendIntent, 0);
Intent deliverIntent = new Intent("DELIVERED_SMS_ACTION");
PendingIntent deliverPI = PendingIntent.getBroadcast(this, 0, deliverIntent, 0);
SmsManager smsManager = SmsManager.getDefault();
List<String> divideContents = smsManager.divideMessage("测试3");
for (String text : divideContents) {
   smsManager.sendTextMessage("12345678;123456789", null, text, sendPI, deliverPI);
}
// 长短信发送方式2
Intent sendIntent2 = new Intent("SENT_SMS_ACTION");
PendingIntent sendPI2 = PendingIntent.getBroadcast(getApplicationContext(), 0, sendIntent2, 0);
Intent deliverIntent2 = new Intent("DELIVERED_SMS_ACTION");
PendingIntent deliverPI2 = PendingIntent.getBroadcast(this, 0, deliverIntent2, 0);
SmsManager smsManager2 = SmsManager.getDefault();
List<String> divideContents2 = smsManager2.divideMessage("测试4");
String[] phone = {"12345678", "123456789"};
for (String p : phone) {
   for (String text : divideContents2) {
       smsManager2.sendTextMessage(p, null, text, sendPI2, deliverPI2);
   }
}

源码参考

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值