1. Download our Official Android App: Forums for Android!

How to show SMS delivery report with Recipient's phone number and message body

Discussion in 'Android Devices' started by ARIJIT DAS, Aug 23, 2017.

  1. ARIJIT DAS

    ARIJIT DAS Lurker
    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    4
    Joined:
    Aug 23, 2017

    Aug 23, 2017
    4
    0
    15
    Hello,

    I am very new to android development.

    I am trying to make an application to send sms using android studio.

    I have already built it too and it is also working very nice BUT when the sms is delivered, I am showing a delivery message as string within a dialog. WHAT I want is: when the sms is delivered, the dialog should show the recipient number as well as the sms body.

    For example: if I am sending a sms to the number: 0000 and the sms message, is: "HELLO", then the dialog will show the delivery report as the following:-
    --------------------------------------
    "Your message, to the number: 0000, with the message:'HELLO', has been successfully delivered."
    --------------------------------------

    Please let me know how can I accomplish this.


    My code, is, as follows:-
    --------------------------------
    Code (Text):
    1. String SENT = "SMS_SENT";
    2. String DELIVERED = "SMS_DELIVERED";
    3.  
    4. final PendingIntent sentPI = PendingIntent.getBroadcast(this, 0,
    5. new Intent(SENT), 0);
    6.  
    7. final PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0,
    8. new Intent(DELIVERED), 0);
    9.  
    10. //---when the SMS has been sent---
    11. registerReceiver(new BroadcastReceiver(){
    12. @Override
    13. public void onReceive(Context arg0, Intent arg1) {
    14. switch (getResultCode())
    15. {
    16. case Activity.RESULT_OK:
    17. Toast.makeText(getBaseContext(), "SMS sent",
    18. Toast.LENGTH_SHORT).show();
    19. break;
    20. case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
    21. Toast.makeText(getBaseContext(), "Generic failure",
    22. Toast.LENGTH_SHORT).show();
    23. break;
    24. case SmsManager.RESULT_ERROR_NO_SERVICE:
    25. Toast.makeText(getBaseContext(), "No service",
    26. Toast.LENGTH_SHORT).show();
    27. break;
    28. case SmsManager.RESULT_ERROR_NULL_PDU:
    29. Toast.makeText(getBaseContext(), "Null PDU",
    30. Toast.LENGTH_SHORT).show();
    31. break;
    32. case SmsManager.RESULT_ERROR_RADIO_OFF:
    33. Toast.makeText(getBaseContext(), "Radio off",
    34. Toast.LENGTH_SHORT).show();
    35. break;
    36. }
    37. }
    38. }, new IntentFilter(SENT));
    39.  
    40. //---when the SMS has been delivered---
    41. registerReceiver(new BroadcastReceiver(){
    42. @Override
    43. public void onReceive(Context arg0, Intent arg1) {
    44. switch (getResultCode())
    45. {
    46. case Activity.RESULT_OK:
    47. //Toast.makeText(getBaseContext(), "SMS delivered",
    48. // Toast.LENGTH_SHORT).show();
    49.  
    50. AlertDialog.Builder builder;
    51. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    52. builder = new AlertDialog.Builder(arg0, android.R.style.Theme_Material_Dialog_Alert);
    53. } else {
    54. builder = new AlertDialog.Builder(arg0);
    55. }
    56. builder.setTitle("SMS Delivered")
    57. .setMessage("SMS Deliverd Successfully" )
    58. .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
    59. public void onClick(DialogInterface dialog, int which) {
    60. }
    61. })
    62. .setIcon(android.R.drawable.ic_dialog_alert)
    63. .show();
    64.  
    65. break;
    66. case Activity.RESULT_CANCELED:
    67. Toast.makeText(getBaseContext(), "SMS not delivered",
    68. Toast.LENGTH_SHORT).show();
    69. break;
    70. }
    71. }
    72. }, new IntentFilter(DELIVERED));
    73.  
    74.  
    75.  
    76. Button button = (Button) findViewById(R.id.button1);
    77.  
    78. button.setOnClickListener(new View.OnClickListener()
    79. {
    80. public void onClick(View v) {
    81.  
    82.  
    83.  
    84. SmsManager sms = SmsManager.getDefault();
    85. sms.sendTextMessage(contactNumber.getText().toString(), null, message.getText().toString(), sentPI, deliveredPI);
    86.  
    87.  
    88. }
    89. });

    --------------------------------

    Please let me know how can I do this and oblige me thereby.




    Thanks.
     

    Advertisement

Share This Page

Loading...