How to get notification data with onNewIntent [closed]

1

I have an application in which when I click on the notification I would like to get the values set in the putExtra notification inside onNewIntent, follow my code to see if anyone can help me.

Intent i = new Intent(this,MainActivity.class);
    i.putExtra("id",id);
    i.putExtra("plan",plan);
    i.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this,0,i,PendingIntent.FLAG_UPDATE_CURRENT);

Now in MainActivity

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    setIntent(intent);

    String id;
    String plan;
    Bundle extras = intent.getExtras();
    if(extras == null) {
        Log.w("extras", "false");
        id= null;
        plan= null;
    } else {
        if(extras.getString("id") != "" && extras.getString("plan") != "") {
            Log.w("extras", "true");
            id= extras.getString("id");
            plan= extras.getString("plan");
        }
    }
}
    
asked by anonymous 18.06.2016 / 23:38

0 answers