不多说 demo传送门:https://download.csdn.net/download/godnessismymine/10767586
安卓实现群发短信:
1.首先获取到即将要群发的联系人的集合:
private List<UploadContactBean> selectContactList = new ArrayList<>();
2.群发短信:
public void sendGroupMessage(String value) {for (UploadContactBean uploadContactBean : selectContactList) {Intent deliverIntent = new Intent(SENT_SMS_ACTION);PendingIntent deliverPI = PendingIntent.getBroadcast(this, 0, deliverIntent, 0);SmsManager smsManager = SmsManager.getDefault();List<String> divideContents = smsManager.divideMessage(value);for (String text : divideContents) {LogUtils.d("MainActivity uploadContactBean.getPhoneNumber() = " + uploadContactBean.getPhoneNumber() + " text = " + text);smsManager.sendTextMessage(uploadContactBean.getPhoneNumber(), null, text, null, deliverPI);}ToastHelper.showShortMessage("Send group message success");}
}
需要的权限:
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<uses-permission android:name="android.permission.WRITE_CONTACTS"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.SEND_SMS" />
常用到的相关方法:
/*** 打电话** @param tel 电话号码*/
private void callPhone1(String tel) {Intent intent = new Intent(Intent.ACTION_DIAL);intent.setData(Uri.parse("tel:" + tel));startActivity(intent);
}/*** 打电话** @param tel 电话号码*/
@SuppressLint("MissingPermission")
private void callPhone2(String tel) {Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + tel));startActivity(intent);
}/*** 发送短信** @param tel 电话号码* @param content 短息内容*/
private void sendMessage1(String tel, String content) {Intent sendIntent = new Intent(SENT_SMS_ACTION);PendingIntent sendPI = PendingIntent.getBroadcast(this, 0, sendIntent, 0);SmsManager smsManager = SmsManager.getDefault();List<String> divideContents = smsManager.divideMessage(content);for (String text : divideContents) {smsManager.sendTextMessage(tel, null, text, sendPI, null);}
}/*** 发送短信** @param tel 电话号码* @param content 短息内容*/
private void sendMessage2(String tel, String content) {Intent deliverIntent = new Intent(DELIVERED_SMS_ACTION);PendingIntent deliverPI = PendingIntent.getBroadcast(this, 0, deliverIntent, 0);SmsManager smsManager = SmsManager.getDefault();List<String> divideContents = smsManager.divideMessage(content);for (String text : divideContents) {smsManager.sendTextMessage(tel, null, text, null, deliverPI);}
}/*** 发送短信(掉起发短信页面)** @param tel 电话号码* @param content 短息内容*/
private void sendMessage3(String tel, String content) {if (PhoneNumberUtils.isGlobalPhoneNumber(tel)) {Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse("smsto:" + tel));intent.putExtra("sms_body", content);startActivity(intent);}
}