Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SMS Delivery Report in Android [closed]

Tags:

android

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 is not displaying SMS delivery report failed otherwise shows report like no service etc.. I want to find SMS sending failed delivery report when my balance is 0.

Help me with any code!

Thanks in Advance!

like image 752
Stack Overflow User Avatar asked Jul 21 '12 05:07

Stack Overflow User


People also ask

Will text messages say delivered if you are blocked Android?

If an Android user has blocked you, Lavelle says, “your text messages will go through as usual; they just won't be delivered to the Android user.” It's the same as an iPhone, but without the “delivered” notification (or lack thereof) to clue you in.

How do I know if SMS is delivered Android?

Now when you send a text message you can tap and hold the message and select “View message details“. On some models, it may be under “View report“. The statuses will show “Received“, “Delivered“, or may simply show the time of delivery. If the message was not delivered, it may show as “Pending” or “None” status.

How do you know if SMS has been delivered?

Turn on Delivery Receipts to find out if your text message was delivered to the recipient. (This option doesn't tell you if the message was read.) On newer phones, open the Messages app and go to Settings > Advanced > Get SMS delivery reports.


1 Answers

BroadcastReceiver sendBroadcastReceiver = new SentReceiver();
    BroadcastReceiver deliveryBroadcastReciever = new DeliverReceiver();;

    @Override
    protected void onPause() {
        // TODO Auto-generated method stub
        super.onPause();

        try {
            unregisterReceiver(sendBroadcastReceiver);
            unregisterReceiver(deliveryBroadcastReciever);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
@Override
protected void onDestroy() {
    // TODO Auto-generated method stub
    super.onDestroy();
    try {
        unregisterReceiver(sendBroadcastReceiver);
        unregisterReceiver(deliveryBroadcastReciever);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

    send_sms.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                if (textView.getText().toString().equals("")
                        | textView.getText().toString().equals(null)) {
                    Toast.makeText(SendSMS.this, enter_ph_no, Toast.LENGTH_LONG)
                            .show();
                } else {


                        sendSMS(textView.getText().toString(), "sms_content");
                        finish();


                }

            }
        });
private void sendSMS(String phoneNumber, String message) {
        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);

        registerReceiver(sendBroadcastReceiver, new IntentFilter(SENT));

        registerReceiver(deliveryBroadcastReciever, new IntentFilter(DELIVERED));
        SmsManager sms = SmsManager.getDefault();
        sms.sendTextMessage(phoneNumber, null, message, sentPI, deliveredPI);


    }

    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;
            }

        }
    }

    class SentReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent arg1) {
            switch (getResultCode()) {
            case Activity.RESULT_OK:
                Toast.makeText(getBaseContext(), sms_sent, Toast.LENGTH_SHORT)
                        .show();
                startActivity(new Intent(SendSMS.this, ChooseOption.class));
                overridePendingTransition(R.anim.animation, R.anim.animation2);
                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;
            }

        }
    }
like image 52
Manikandan Avatar answered Sep 29 '22 13:09

Manikandan