android 自动发短信
android.telephony.SmsManager smsManager = android.telephony.SmsManager.getDefault();
ArrayList<String> messages = smsManager.divideMessage(content);
/* for (String text : messages) {
smsManager.sendTextMessage(smsNumber, null, text, null, null);//短信内容少于70个字符
}*/
smsManager.sendMultipartTextMessage(smsNumber, null, messages, null, null);
//获取SmsManager对象,下面的判断可有可无,可又直接返回 SmsManager.getDefault();
private static SmsManager (subId) { (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) { SmsManager.getSmsManagerForSubscriptionId(subId);//获取指定卡槽的SmsManager对象 } { SmsManager.getDefault(); } }
自动发送信息完整功能代码:
public static void AutoSentSMS(Context context,String address,String messageBody){
SubscriptionManager mManager = context.getSystemService(SubscriptionManager.class);
final List<SubscriptionInfo> subscriptions = mManager.getActiveSubscriptionInfoList();
int subId = -1;
if(subscriptions != null && subscriptions.size() > 0){
subId = subscriptions.get(0).getSubscriptionId();
}else{
android.util.Log.e(TAG,"Please insert SIM card");
return;
}
SmsManager smsManager = SmsManager.getDefault();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
}
ArrayList<String> messages = smsManager.divideMessage(messageBody);
smsManager.sendMultipartTextMessage(address, null, messages, null, null);
android.util.Log.e(TAG,"AutoReplySOSSMS end");
}
评论