嘿我已经使用android创建示例应用程序要发送Sms特定的数字列表知道工作正常,否则我使用“广播接收器”来检查已发送和交付的状态这也可以正常工作。我将得到他们两个的Toast 。但还有一个问题 如何获取手机号码? 我需要的只是手机号码未送达请给我解决方案
示例代码行:
mSmsManager = SmsManager.getDefault();
sentReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
switch(getResultCode()){
case Activity.RESULT_OK:
sentSMS++;
sentCounter.setText(getString(R.string.counter_sent) + sentSMS + "/" + totalSMS + "\n" + getString(R.string.counter_delivered) + deliveredSMS + "/" + totalSMS);
Toast.makeText(context, getString(R.string.sms_sent), Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
Toast.makeText(context, getString(R.string.sms_generic_failure), Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_NO_SERVICE:
Toast.makeText(context, getString(R.string.sms_no_service), Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_NULL_PDU:
Toast.makeText(context, getString(R.string.sms_null_pdu), Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_RADIO_OFF:
Toast.makeText(context, getString(R.string.sms_radio_off), Toast.LENGTH_SHORT).show();
break;
}
}
};
deliveredReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
switch(getResultCode()){
case Activity.RESULT_OK:
deliveredSMS++;
sentCounter.setText(getString(R.string.counter_sent) + sentSMS + "/" + totalSMS + "\n" + getString(R.string.counter_delivered) + deliveredSMS + "/" + totalSMS);
Toast.makeText(context, getString(R.string.sms_delivered), Toast.LENGTH_SHORT).show();
break;
case Activity.RESULT_CANCELED:
Toast.makeText(context, getString(R.string.sms_failed_delivery), Toast.LENGTH_SHORT).show();
break;
}
}
};
registerReceiver(sentReceiver, new IntentFilter(SENT));
registerReceiver(deliveredReceiver, new IntentFilter(DELIVERED));
}
答案 0 :(得分:-1)
要跟踪传出SMS的传输和传递,请实现并注册广播接收器,以便在创建传递给sendTextMessage方法的Pending Intents时侦听您指定的操作。在此示例中,我们将使用{ {1}},Intent
和PendingIntent
来跟踪邮件投放。
当邮件成功发送或失败时,将触发第一个Pending Intent参数(sentIntent)。接收此Intent的Broadcast接收器的结果代码将是以下之一。
Broadcastreceiver
仅在收件人收到您的短信后才会触发第二个待处理参数(Activity.RESULT_OK - To indicate a successful transmission.
Sms.Manager.RESULT_ERROR_GENERIC_FAILURE - To indicate a nonspecific failure
Sms.Manager.RESULT_ERROR_RADIO_OFF - To indicate the phone radio is turned off
Sms.Manager.RESULT_ERROR_NULL_PDU - To indicate a PDU failure.
SmsManager.RESULT_ERROR_NO_SERVICE - To indicate that no cellular service is currently available.
)。
在发送和发送事件之后,我们通过Toast显示了相应的消息。
deliveryIntent