Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to make SMS sent confirmation program in android

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 381
    Comment on it

    If you want to create sms delivery app you can use my below code. In the below code I have used Intent , PandingIntent and Broadcastreceiver. In the below code I have also used Toast function to deliver SMS notification. See the below example it will clearly described how to make sent sms confirmation app.

    1. public class MainActivity extends Activity {
    2. Button btnSend;
    3. EditText etPhoneNo;
    4. EditText etMsg;
    5.  
    6. @Override
    7. protected void onCreate(Bundle savedInstanceState) {
    8. super.onCreate(savedInstanceState);
    9. setContentView(R.layout.activity_main);
    10. etPhoneNo = (EditText) findViewById(R.id.phno);
    11. etMsg = (EditText) findViewById(R.id.smstxt);
    12. btnSend = (Button) findViewById(R.id.send);
    13.  
    14. btnSend.setOnClickListener(new OnClickListener() {
    15. @Override
    16. public void onClick(View v) {
    17. String phoneNo = etPhoneNo.getText().toString();
    18. String msg = etMsg.getText().toString();
    19. try {
    20.  
    21. String SENT = "sent";
    22. String DELIVERED = "delivered";
    23.  
    24. Intent sentIntent = new Intent(SENT);
    25. /*Create Pending Intents*/
    26. PendingIntent sentPI = PendingIntent.getBroadcast(
    27. getApplicationContext(), 0, sentIntent,
    28. PendingIntent.FLAG_UPDATE_CURRENT);
    29.  
    30. Intent deliveryIntent = new Intent(DELIVERED);
    31.  
    32. PendingIntent deliverPI = PendingIntent.getBroadcast(
    33. getApplicationContext(), 0, deliveryIntent,
    34. PendingIntent.FLAG_UPDATE_CURRENT);
    35. /* Register for SMS send action */
    36. registerReceiver(new BroadcastReceiver() {
    37.  
    38. @Override
    39. public void onReceive(Context context, Intent intent) {
    40. String result = "";
    41.  
    42. switch (getResultCode()) {
    43.  
    44. case Activity.RESULT_OK:
    45. result = "Transmission successful";
    46. break;
    47. case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
    48. result = "Transmission failed";
    49. break;
    50. case SmsManager.RESULT_ERROR_RADIO_OFF:
    51. result = "Radio off";
    52. break;
    53. case SmsManager.RESULT_ERROR_NULL_PDU:
    54. result = "No PDU defined";
    55. break;
    56. case SmsManager.RESULT_ERROR_NO_SERVICE:
    57. result = "No service";
    58. break;
    59. }
    60.  
    61. Toast.makeText(getApplicationContext(), result,
    62. Toast.LENGTH_LONG).show();
    63. }
    64.  
    65. }, new IntentFilter(SENT));
    66. /* Register for Delivery event */
    67. registerReceiver(new BroadcastReceiver() {
    68.  
    69. @Override
    70. public void onReceive(Context context, Intent intent) {
    71. Toast.makeText(getApplicationContext(), "Deliverd",
    72. Toast.LENGTH_LONG).show();
    73. }
    74.  
    75. }, new IntentFilter(DELIVERED));
    76.  
    77. /*Send SMS*/
    78. SmsManager smsManager = SmsManager.getDefault();
    79. smsManager.sendTextMessage(phoneNo, null, msg, sentPI,
    80. deliverPI);
    81. } catch (Exception ex) {
    82. Toast.makeText(getApplicationContext(),
    83. ex.getMessage().toString(), Toast.LENGTH_LONG)
    84. .show();
    85. ex.printStackTrace();
    86. }
    87. }
    88. });
    89.  
    90. }
    91.  
    92. @Override
    93. public boolean onCreateOptionsMenu(Menu menu) {
    94. // Inflate the menu; this adds items to the action bar if it is present.
    95. getMenuInflater().inflate(R.menu.activity_main, menu);
    96. return true;
    97. }
    98.  
    99. }

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Reset Password
Fill out the form below and reset your password: