How to receive params in intent for broadcast

51 Views Asked by At
Integer id_user = 1;
Intent registration= new Intent("com.google.android.c2dm.intent.REGISTER");
                                registration.putExtra("app", PendingIntent.getBroadcast(getBaseContext(),0,new Intent(),0));
                                registration.putExtra("sender",project_number);
                                startService(registration);

i need put extra similar

registration.putExtra("id_user",id_user);

and recieved in broadclass

public class resquest extends BroadcastReceiver {

NEED CATCH HERE..... a USER_ID

    @Override
    public void onReceive(Context context, Intent intent) {
      .....Code here 
    }
}

Regards!

1

There are 1 best solutions below

0
On

First of all you need to send in the user id to be able to fetch it:

Integer id_user = 1;
Intent registration= new Intent("com.google.android.c2dm.intent.REGISTER");
                            registration.putExtra("app", PendingIntent.getBroadcast(getBaseContext(),0,new Intent(),0));
                            registration.putExtra("sender",project_number);
                            registration.putExtra("id_user", id_user.intValue());
                            startService(registration);

Then you can fetch it like this

public class resquest extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        int id_user = i.getExtras().getInt("id_user");
    }
}