0

Below i am having code for two notifications and in intent i am passing extras with key1 and key2 but in NotificationPillDescription.class i am only able to get key1 using getExtras.

// Notification Code For First Notification

Notification notification = new Notification(R.drawable.ic_launcher, "Take your morning pill!", System.currentTimeMillis());
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    notifyIntent = new Intent(getApplicationContext(), NotificationPillDescription.class);
    Bundle extras = new Bundle();
    extras.putString("Key1", String.valueOf(1));
    notifyIntent.putExtras(extras);

    contentIntent = PendingIntent.getActivity(getApplicationContext(), 0, notifyIntent, 0);
    notification.setLatestEventInfo(this, "Take your Morning pill!", "My Drug", contentIntent);
                        notificationManager.notify(dataProvider.notificationId++, notification);

// Notification Code For Second Notification

notifyIntent = new Intent(getApplicationContext(), NotificationPillDescription.class);
        Bundle extras = new Bundle();
        extras.putString("Key2", String.valueOf(2));
        notifyIntent.putExtras(extras);

        contentIntent = PendingIntent.getActivity(getApplicationContext(), 0, notifyIntent, 0);
        notification.setLatestEventInfo(this, "Take your Morning pill!", "My Drug", contentIntent);
                            notificationManager.notify(dataProvider.notificationId++, notification);

//Code for NotificationPillDescription.class

Bundle extras = getIntent().getExtras();
            if(extras != null){
                if(extras.containsKey(String.valueOf(1)))
                {
                   Log.d("Pill Id0",extras.getString(String.valueOf(1)) );

                }
                else
                {
                    Log.d("Pill Id1",extras.getString(String.valueOf(2)) );
                }
            }               
teacher
  • 1,005
  • 3
  • 15
  • 27

2 Answers2

0

It should be,

extras.getString("Key1") and extras.getString("Key2")

instead of

extras.getString(String.valueOf(1)) && extras.getString(String.valueOf(2))

Lalit Poptani
  • 67,150
  • 23
  • 161
  • 242
0

Have a look here. It describes how to pass a bundle. I think your extras.getstring might not be enough. you might also not need to declare a bundle if you're using putextras.

Here:

Passing a Bundle on startActivity()?

This might be helpful too:

putExtras multiple putString not working

Community
  • 1
  • 1
SunnySonic
  • 1,318
  • 11
  • 37