/** 发送与接收的广播 **/
String SENT_SMS_ACTION = "SENT_SMS_ACTION";
<span style="font-family: Arial, Helvetica, sans-serif;">//短信发送</span>
private void sendMessage(String phone, String message) {
//如果不考虑短信发送是否成功的话,可以使用PendingIntent.getBroadcast
PendingIntent pi = PendingIntent.getBroadcast(this, 0, new Intent(
<span style="color:#ff0000;">SENT_SMS_ACTION</span>), 0);
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phone, null, message, pi, null);
}
//短信广播接受
class SMSSendResultReceiver extends BroadcastReceiver {
<span style="white-space:pre"> </span>@Override
<span style="white-space:pre"> </span>public void onReceive(Context context, Intent intent) {
<span style="white-space:pre"> </span>switch (getResultCode()) {
<span style="white-space:pre"> </span>case Activity.RESULT_OK:
<span style="white-space:pre"> </span>break;
<span style="white-space:pre"> </span>case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
<span style="white-space:pre"> </span>case SmsManager.RESULT_ERROR_RADIO_OFF:
<span style="white-space:pre"> </span>case SmsManager.RESULT_ERROR_NULL_PDU:
<span style="white-space:pre"> </span>default:
<span style="white-space:pre"> </span>Toast.makeText(context, "发送短信失败!", 1).show();
<span style="white-space:pre"> </span>Log.i(TAG, "-----------------------------发送短信失败!");
<span style="white-space:pre"> </span>break;
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>}
}
private SMSSendResultReceiver mSMSReceiver = new SMSSendResultReceiver();
private IntentFilter mSMSResultFilter = new IntentFilter();
//添加action,注册广播
mSMSResultFilter.addAction(SENT_SMS_ACTION);
registerReceiver(mSMSReceiver, mSMSResultFilter);
最后
以上就是坚定高山最近收集整理的关于发送短信及其判断是否发送成功的全部内容,更多相关发送短信及其判断是否发送成功内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复