1

I have done the firebase notification. I can be able to get the multiple notification in the notification bar. When I pressed one notification icons from the notification bar then it's redirecting to the last received screen. then if I pressed the pending icons from the notification bar then nothing happen. this is my code

 private void sendNotification(Map<String, String> data) {
    Intent intent = null;
    String messageBody = data.get("Message");
    String referenceKey = data.get("ReferenceKey");
    String referenceValueFromFCM = data.get("ReferenceValue");

    if (LocalRepository.getInstance().isAuthenticated()) {
     PromotionData promotionData = new PromotionData();

            if (!TextUtils.isEmpty(referenceValue) && TextUtils.isDigitsOnly(referenceValue)) {
                promotionData.promotionId = Integer.parseInt(referenceValue);

            }
    intent.putExtra("key", referenceKey);
     intent.putExtra("data", promotionData);
     intent.putExtra("value", referenceValue);
intent = new Intent(this, DashboardActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    long[] pattern = {250, 250, 250, 250, 250};
    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_notification)
            .setContentTitle(getString(R.string.app_name))
            .setContentText(messageBody)
            .setAutoCancel(true)
            .setVibrate(pattern)
            .setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

    NotificationManager notificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    notificationManager.notify(AppUtil.getNotificationId() /* ID of notification */, notificationBuilder.build());

This is my manifest

 <activity
        android:name=".views.dashboard.DashboardActivity"
        android:screenOrientation="portrait"
        android:exported="true"
        android:theme="@style/AppTheme.NoActionBar"
        android:windowSoftInputMode="stateAlwaysHidden" />

This is the dashboard navigation activity

 String key = getIntent().getStringExtra("key");
            String promotionID = getIntent().getStringExtra("value");
            PromotionData promotionData = getIntent().getParcelableExtra("data");

            if (!TextUtils.isEmpty(promotionID) && (!TextUtils.isEmpty(key))) {
                Intent intent = null;
                switch (key) {
                    case Repository.ModuleCode.WHATS_NEWS:
                         if (hasPromotionId) {
                        whatsNew();
                        intent = new Intent(this, WhatsNewDetailActivity.class);
                        intent.putExtra("data", promotionData);
                        intent.putExtra("pushID", pushID);
                        startActivity(intent);
                         }else{
                          whatsNew(); // this is fragment
                         }
                        break;

                    case Repository.ModuleCode.PROMOTION:
                         if (hasPromotionId) {
                        promotion();
                        intent = new Intent(this, PromotionDetailActivity.class);
                        intent.putExtra("data", promotionData);
                        intent.putExtra("pushID", pushID);
                        startActivity(intent);
                         }else{
                           promotion(); // this is fragment
                         }
                        break;

can you please advise me Thanks in advance.

AngelJanniee
  • 613
  • 1
  • 11
  • 30
  • where is code of passing values using Intent for **key** , **value** , **data** ? – Rajesh Satvara Dec 06 '16 at 09:49
  • see my updated code for the passing value, This is my issue, I am getting the notification, if there 2 notification in the mobile notification bar then if I pressed any of the notification icons then it will redirect to the last received notification's navigation screen, not the exact screen. then if I pressed the another icons then nothing happen. – AngelJanniee Dec 06 '16 at 09:55
  • visit this link for get idea for multiple notification and go to exact Activity http://stackoverflow.com/questions/12968280/android-multiple-notifications-and-with-multiple-intents – Rajesh Satvara Dec 06 '16 at 10:05

2 Answers2

1

You can use this answer for understanding how to pass value on Activity using Notification. Here's a link which might be helpful

Only you have to pass values with the Intent like this,

Intent intent = new Intent(this, yourActivityClass.class);
intent.putExtra("msg",messageBody);
Community
  • 1
  • 1
Rajesh Satvara
  • 3,842
  • 2
  • 30
  • 50
1

I have find out the answer for my question. When I am passing the values with Intent, should use the

intent.setData

then its working for multiple notification.

This is my updated code for navigate the exact screen.

Intent intent = null;
    String messageBody = data.get("Message");
    String referenceKey = data.get("ReferenceKey");
    String referenceValue = data.get("ReferenceValue");
    String pushID = data.get("PushId");


    PromotionData promotionData = new PromotionData();//item id
    if (!TextUtils.isEmpty(referenceKey)) {
        if (!TextUtils.isEmpty(referenceValue) && TextUtils.isDigitsOnly(referenceValue)) {
            promotionData.promotionId = Integer.parseInt(referenceValue);

        }
    }

    if (LocalRepository.getInstance().isAuthenticated()) {
        intent = new Intent(this, DashboardActivity.class);
        intent.setData(new Uri.Builder().scheme(referenceKey).build());
        intent.putExtra("pushID", pushID);
        intent.putExtra("data", promotionData);
        intent.putExtra("key", referenceKey);
        intent.putExtra("value", referenceValue);
    } else {
        intent = new Intent(this, LoginActivity.class);
        intent.setData(new Uri.Builder().scheme(referenceKey).build());
        intent.putExtra("pushID", pushID);
        intent.putExtra("data", promotionData);
        intent.putExtra("key", referenceKey);
        intent.putExtra("value", referenceValue);
    }

    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    long[] pattern = {250, 250, 250, 250, 250};
    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_notification)
            .setContentTitle(getString(R.string.app_name))
            .setContentText(messageBody)
            .setAutoCancel(true)
            .setVibrate(pattern)
            .setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

    NotificationManager notificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    notificationManager.notify(AppUtil.getNotificationId() /* ID of notification */, notificationBuilder.build());
}

Here should use this line for the exact page navigation. this is firebase bug. intent.setData(new Uri.Builder().scheme(referenceKey).build()); We can pass whatever the String instead of referenceKey.

AngelJanniee
  • 613
  • 1
  • 11
  • 30