0

how to sent parameter to another activity after receiving SMS I try but its show error

The method putExtra(String, boolean) in the type Intent is not applicable for the arguments (Bundle)

below is my code:

public class SmsReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) 
{
    //---get the SMS message passed in---
    Bundle bundle = intent.getExtras();        
    SmsMessage[] msgs = null;
    String str = "";  


    if (bundle != null)
    {
        //---retrieve the SMS message received---
        Object[] pdus = (Object[]) bundle.get("pdus");
        msgs = new SmsMessage[pdus.length];            
        for (int i=0; i<msgs.length; i++){
            msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
            str += msgs[i].getMessageBody().toString();
        }

        Intent l = new Intent(context,AgAppMenu.class);
        Bundle bundle2 = new Bundle();
        bundle.putString("msg", str);
        l.putExtra(bundle);

        l.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(l);
        Toast.makeText(context, "SucessFull Login", Toast.LENGTH_SHORT).show();
Roham Rafii
  • 2,929
  • 7
  • 35
  • 49
Hayya ANAM
  • 575
  • 2
  • 14
  • 38

4 Answers4

0

you can put the string directly into the intent:

l.putExtra("msg", str);

and then get it using:

getIntent().getStringExtra("msg");

but if you wanna use bundles, i think here you should refere to bundle2:

Intent l = new Intent(context,AgAppMenu.class);
        Bundle bundle2 = new Bundle();
        bundle2.putString("msg", str);

    l.putExtras(bundle2);
Nermeen
  • 15,883
  • 5
  • 59
  • 72
  • this error The method putExtra(String, boolean) in the type Intent is not applicable for the arguments (Bundle) – Hayya ANAM Sep 11 '12 at 08:33
  • to pass bundle use l.putExtras(bundle2); using putExtra() you have to respect the arguments, here putExtra(String, boolean) is expecting a boolean – Nermeen Sep 11 '12 at 08:37
0

You need to set the bundle by using Intent.putExtras(Bundle)

Avadhani Y
  • 7,566
  • 19
  • 63
  • 90
gheese
  • 1,170
  • 1
  • 11
  • 17
0

If you want to pass a bundle use putExtras (Bundle extras) and not putExtra

Alexis C.
  • 91,686
  • 21
  • 171
  • 177