Question

In my Application I'm sending text sms using SMS Manager. To check whether messages is sent or not I'm using Toast. Instead of Toast I want to get SMS Delivery Report.I am trying many examples but, one flow not displaying delivery report like if my balance is 0 when SMS sending in my code I want to find SMS sending failed delivery report when my balance is 0.

Code:

String phoneNo = phno.getText().toString();
String smsBody = body.getText().toString(); 
 //Selected Messages to report to 1909
{
             try
             {

                 SmsManager smsManager = SmsManager.getDefault();
                 smsManager.sendTextMessage(phoneNo, null, smsBody, null, null); 
                 Toast.makeText(getApplicationContext(), "SMS Sent to: "+phoneNo,Toast.LENGTH_SHORT).show();
             }                           
             catch (Exception e)
             {
                 //Error Occurred if No Messages Selected 
                 Toast.makeText(getApplicationContext(),"SMS failed, please try again later!",Toast.LENGTH_SHORT).show();
                 e.printStackTrace();
             }
             }

    }

Help me with any code!

Thanx in Adavance !!

Was it helpful?

Solution

try this link,

SMS Delivery Report in Android

 class deliverReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, 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;
            }

        }
    }

don't forgot to add these permissions in manifest

<uses-permission android:name="android.permission.RECEIVE_SMS" /> 
<uses-permission android:name="android.permission.SEND_SMS" /> 
<uses-permission android:name="android.permission.READ_SMS" /> 
<uses-permission android:name="android.permission.WRITE_SMS" /> 

OTHER TIPS

to send sms use this method

public void sendTextMessage (String destinationAddress, String scAddress, String text, 
PendingIntent sentIntent, PendingIntent deliveryIntent)

eg

sms.sendTextMessage(phoneNumber, null, message, sentPI, deliveredPI);

where deliveredPI is PendingIntent.

the last parameter is deliveryIntent which is fired by android on "successful delivery of message" to the recipient.

so now u need to have a BroadcastReceiver to get this msg.

BroadcastReceiver deliveryBroadcastReciever = new deliverReceiver();

class deliverReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, 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;
        }

    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top