如何知道短信是否发送成功?
我检查了文档,但没有找到解决问题的方法...我怎么知道?
//---when the SMS has been sent---
registerReceiver(new BroadcastReceiver(){
@Override
public void onReceive(Context arg0, Intent arg1) {
switch (getResultCode())
{
case Activity.RESULT_OK:
Toast.makeText(getBaseContext(), "SMS sent",Toast.LENGTH_SHORT).show();
getServerData("http://site.com","id",Id);
break;
case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
System.exit(0);
Toast.makeText(getBaseContext(), "Generic failure", Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_NO_SERVICE:
System.exit(0);
Toast.makeText(getBaseContext(), "No service", Toast.LENGTH_SHORT).show();
break;
case SmsManager.STATUS_ON_SIM_UNSENT:
System.exit(0);
Toast.makeText(getBaseContext(), "Message unsent", Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_NULL_PDU:
System.exit(0);
Toast.makeText(getBaseContext(), "Null PDU", Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_RADIO_OFF:
System.exit(0);
Toast.makeText(getBaseContext(), "Radio off", Toast.LENGTH_SHORT).show();
break;
case SmsManager.STATUS_ON_SIM_SENT :
System.exit(0);
Toast.makeText(getBaseContext(), "Message sent", Toast.LENGTH_SHORT).show();
break;
}
}
}, new IntentFilter(SENT));
//---when the SMS has been delivered---
registerReceiver(new BroadcastReceiver(){
@Override
public void onReceive(Context arg0, Intent arg1) {
switch (getResultCode())
{
case Activity.RESULT_OK:
//Toast.makeText(getBaseContext(), "SMS delivered", Toast.LENGTH_SHORT).show();
break;
case Activity.RESULT_CANCELED:
// Toast.makeText(getBaseContext(), "SMS not delivered", Toast.LENGTH_SHORT).show();
break;
}
}
}, new IntentFilter(DELIVERED));
if(isMobileAvailable(getApplicationContext()) == true){
Toast.makeText(getApplicationContext(), "Reseau mobile: OK !", Toast.LENGTH_LONG).show();
ArrayList<String> parts = (ArrayList<String>) splitInChunks(message, 120);
for (String str : parts) {
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null, str, null, null);
}
getServerData("http://site.com","id",Id);
}else
Toast.makeText(getApplicationContext(), "Reseau mobile: NOK !", Toast.LENGTH_LONG).show();
}
我只是想知道我的短信是否成功发送...谢谢你!