调用系统的发短信功能
Uri smsToUri = Uri.parse("smsto:接收方号码 ");// Uri smsToUri =Uri.parse("smsto:"); 进入发送短信的界面没有发送给谁的号码
Intent intent = new Intent(Intent.ACTION_SENDTO,smsToUri);
intent.putExtra("sms_body",发送内容);//发送内容
startActivity(intent);
调用系统的短信群发
//smsto 后面可以没有手机号码,此时会进入手机发送短信界面而没有发送对象
Uri smsToUri =Uri.parse("smsto:15901010673,18303279749");//号码之间可以为,也可以为;
Intent intent = new Intent(Intent.ACTION_SENDTO,smsToUri);
intent.putExtra("sms_body", "你好");//发送内容
startActivity(intent);
使用SmsManager发送短信
SmsManager smsManager=SmsManager.getDefault();
Intent deliveryIntent=new Intent("sms_to");//参数是自己定义的action
//定义未知意图,当触发后发送广播,实例化时的intent就是定义发送广播时的intent(intent 中定义了该广播的隐式意图)
PendingIntent sendIntent=PendingIntent.getBroadcast(this, 100, deliveryIntent, PendingIntent.FLAG_CANCEL_CURRENT);
//定义广播监听短信是否发送成功
registerReceiver(new BroadcastReceiver(){
@Override
public void onReceive(Context arg0, Intent arg1) {
switch(getResultCode()){
case Activity.RESULT_OK:
Toast.makeText(MainActivity.this, "短信已发送成功", Toast.LENGTH_LONG).show();
break;
default:
Toast.makeText(MainActivity.this, "短信已发送失败", Toast.LENGTH_LONG).show();
break;
}
}
}, new IntentFilter("sms_to"));
//定义未知意图,当触发后发送广播,实例化时的intent就是定义发送广播时的intent
PendingIntent receiverIntent=PendingIntent.getBroadcast(this, 80, new Intent("receive"), PendingIntent.FLAG_CANCEL_CURRENT);
//注册广播监听对方是否接收到短信了
registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context arg0, Intent arg1) {
switch(getResultCode()){
case Activity.RESULT_OK:
Toast.makeText(MainActivity.this, "对方已经接收短信", Toast.LENGTH_LONG).show();
break;
default:
break;
}
}
}, new IntentFilter("receive"));
//调用发送短信
smsManager.sendTextMessage(numberTwo, null, "你好", sendIntent, receiverIntent);
对于使用SmsManager群发短信我们可以遍历电话号码循环重复发送短信