Android Sms Intent Bundle Toast Info Not Updating
I am sending 2 sms messages, i want to have 2 toast messages with 1) 'SMS sent - first number' and 2) 'SMS sent - second number' however, am getting 2 toast messages both showing
Solution 1:
What you are doing is -using the same intent.So you have to update the intents and change the request code so that result not overlapped . See the following.Following code will work.
registerReceiver(new BroadcastReceiver(){
@Override
public void onReceive(Context arg0, Intent arg1) {
switch (getResultCode())
{
case Activity.RESULT_OK:
Toast.makeText(getBaseContext(), "SMS sent - " + arg1.getStringExtra("SendTo"),
Toast.LENGTH_LONG).show();
break;
}
}
}, new IntentFilter(SENT));
SmsManager sms = SmsManager.getDefault();
Intent intent = new Intent(SENT);
intent.putExtra("SendTo", "first number");
PendingIntent sentIntents = PendingIntent.getBroadcast(this, 0, intent,PendingIntent.FLAG_UPDATE_CURRENT);
sms.sendTextMessage("5556", null,message, sentIntents, null);
Intent intent1 = new Intent(SENT);
intent1.putExtra("SendTo", "second number");
PendingIntent sentIntents1 = PendingIntent.getBroadcast(this, 1, intent1, PendingIntent.FLAG_UPDATE_CURRENT);
sms.sendTextMessage("5556", null, message, sentIntents1, null);
Solution 2:
Change to this:
Toast.makeText(this, "First number", Toast.LENGTH_SHORT).show();
sms.sendTextMessage("1234", null, message, null, null);
Toast.makeText(this, "Second number", Toast.LENGTH_SHORT).show();
sms.sendTextMessage("456", null, message, mull, null);
Post a Comment for "Android Sms Intent Bundle Toast Info Not Updating"