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:-
--------------------------------
String SENT = "SMS_SENT";
String DELIVERED = "SMS_DELIVERED";
final PendingIntent sentPI = PendingIntent.getBroadcast(this, 0,
new Intent(SENT), 0);
final PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0,
new Intent(DELIVERED), 0);
//---when the SMS has been sent---
registerReceiver(new BroadcastReceiver(){
@Override
public void onReceive(Context arg0, Intent arg1) {
switch (getResultCode())
{
case Activity.RESULT_OK:
Toast.makeText(getBaseContext(), "SMS sent",
Toast.LENGTH_SHORT).show();
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;
}
}
}, new IntentFilter(SENT));
//---when the SMS has been delivered---
registerReceiver(new BroadcastReceiver(){
@Override
public void onReceive(Context arg0, Intent arg1) {
switch (getResultCode())
{
case Activity.RESULT_OK:
//Toast.makeText(getBaseContext(), "SMS delivered",
// Toast.LENGTH_SHORT).show();
AlertDialog.Builder builder;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
builder = new AlertDialog.Builder(arg0, android.R.style.
Theme_Material_Dialog_Alert);
} else {
builder = new AlertDialog.Builder(arg0);
}
builder.setTitle("SMS Delivered")
.setMessage("SMS Deliverd Successfully" )
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener
() {
public void onClick(DialogInterface dialog, int which) {
}
})
.setIcon(android.R.drawable.ic_dialog_alert)
.show();
break;
case Activity.RESULT_CANCELED:
Toast.makeText(getBaseContext(), "SMS not delivered",
Toast.LENGTH_SHORT).show();
break;
}
}
}, new IntentFilter(DELIVERED));
Button button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v) {
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(contactNumber.getText().toString(), null, message.
getText().toString(), sentPI, deliveredPI);
}
});
--------------------------------
Please let me know how can I do this and oblige me thereby.
Thanks.
--
You received this message because you are subscribed to the Google Groups
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/android-developers.
To view this discussion on the web visit
https://groups.google.com/d/msgid/android-developers/e76148fa-ba90-43d2-aefd-5d3db6bcaf5e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.