I have a problem, not that major problem but since i implemented sendMultipartTextMessage on my codes the toast of “SMS Sent” or any other toast wont show up. I dunno if the sms is successfully sent or not. What should I do? Here’s the code:
private void sendSMS(String phoneNo, String message, boolean split)
{
String SENT = "SMS_SENT";
String DELIVERED = "SMS_DELIVERED";
PendingIntent sentPI = PendingIntent.getBroadcast(this, 0,
new Intent(SENT), 0);
PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0,
new Intent(DELIVERED), 0);
SmsManager sms = SmsManager.getDefault();
if (!split) {
Log.d("SMSTest", "Sending single message: " + message);
} else {
Log.d("SMSTest", "Sending '" + message + "' in multiple parts.");
ArrayList<String> parts = sms.divideMessage(message);
Log.d("SMSTest", parts.size() + " parts:");
for (String string : parts) {
Log.d("SMSTest", string);
}
ArrayList<PendingIntent> sentList = new ArrayList<PendingIntent>();
sentList.add(sentPI);
ArrayList<PendingIntent> deliveredList = new ArrayList<PendingIntent>();
deliveredList.add(deliveredPI);
sms.sendMultipartTextMessage(phoneNo, null, parts, sentList,
deliveredList);
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();
break;
case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
Toast.makeText(getBaseContext(), "Generic failure",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_NO_SERVICE:
Toast.makeText(getBaseContext(), "No service",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_NULL_PDU:
Toast.makeText(getBaseContext(), "Null PDU",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_RADIO_OFF:
Toast.makeText(getBaseContext(), "Radio off",
Toast.LENGTH_SHORT).show();
break;
}
}
}, new IntentFilter(SENT));
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));
}
}
}
You should never implement a switch without default case. Make one and display the value of
getResultCode(), than you might see at least what is returned. This should help you investigate the behavior further.Sample: