Hi, you miss the mention of the brodcast recipient name in your intentions.
Please try below code which works great for me.
ArrayList<PendingIntent> sentPendingIntents = new ArrayList<PendingIntent>(); ArrayList<PendingIntent> deliveredPendingIntents = new ArrayList<PendingIntent>(); PendingIntent sentPI = PendingIntent.getBroadcast(mContext, 0, new Intent(mContext, SmsSentReceiver.class), 0); PendingIntent deliveredPI = PendingIntent.getBroadcast(mContext, 0, new Intent(mContext, SmsDeliveredReceiver.class), 0); try { SmsManager sms = SmsManager.getDefault(); ArrayList<String> mSMSMessage = sms.divideMessage(message); for (int i = 0; i < mSMSMessage.size(); i++) { sentPendingIntents.add(i, sentPI); deliveredPendingIntents.add(i, deliveredPI); } sms.sendMultipartTextMessage(phoneNumber, null, mSMSMessage, sentPendingIntents, deliveredPendingIntents); } catch (Exception e) { e.printStackTrace(); Toast.makeText(mContext, "SMS sending failed...", Toast.LENGTH_SHORT).show(); }
Create a receiver for the receiver to send SMS as shown below.
public class SmsSentReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { switch (getResultCode()) { case Activity.RESULT_OK: Toast.makeText(context, "SMS Sent" + intent.getIntExtra("object", 0), Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_GENERIC_FAILURE: Toast.makeText(context, "SMS generic failure", Toast.LENGTH_SHORT) .show(); break; case SmsManager.RESULT_ERROR_NO_SERVICE: Toast.makeText(context, "SMS no service", Toast.LENGTH_SHORT) .show(); break; case SmsManager.RESULT_ERROR_NULL_PDU: Toast.makeText(context, "SMS null PDU", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_RADIO_OFF: Toast.makeText(context, "SMS radio off", Toast.LENGTH_SHORT).show(); break; } }
Create another broadcast receiver for sms as shown below.
public class SmsDeliveredReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent arg1) { switch (getResultCode()) { case Activity.RESULT_OK: Toast.makeText(context, "SMS delivered", Toast.LENGTH_SHORT).show(); break; case Activity.RESULT_CANCELED: Toast.makeText(context, "SMS not delivered", Toast.LENGTH_SHORT).show(); break; } }
}
Finally declare the receiver in the manifest.
<receiver android:name=".receiver.SmsSentReceiver" > </receiver> <receiver android:name=".receiver.SmsDeliveredReceiver" > </receiver>