Уведомление Android Firebase не переходит на нужную страницу

Я сделал уведомление firebase. Я могу получить несколько уведомлений на панели уведомлений. Когда я нажимал один значок уведомлений на панели уведомлений, он перенаправлялся на последний полученный экран. затем, если я нажму ожидающие значки на панели уведомлений, ничего не произойдет. это мой код

 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());

это мой манифест

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

Это действие навигации по приборной панели.

 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;

не могли бы вы посоветовать мне спасибо заранее.


person AngelJanniee    schedule 06.12.2016    source источник
comment
где код передачи значений с использованием Intent для key , value , data ?   -  person Rjz Satvara    schedule 06.12.2016
comment
см. мой обновленный код для передаваемого значения. Это моя проблема, я получаю уведомление, если на панели мобильных уведомлений есть 2 уведомления, а затем, если я нажму любой из значков уведомлений, он будет перенаправлен на экран навигации последнего полученного уведомления, не тот экран. затем, если я нажму другие значки, ничего не произойдет.   -  person AngelJanniee    schedule 06.12.2016
comment
посетите эту ссылку, чтобы получить представление о множественных уведомлениях, и перейдите к точной активности stackoverflow.com/questions/12968280/   -  person Rjz Satvara    schedule 06.12.2016


Ответы (2)


Вы можете использовать этот ответ, чтобы понять, как передать значение Activity с помощью Notification. Вот ссылка, которая может быть полезна

Только вам нужно передавать значения с помощью Intent вот так,

Intent intent = new Intent(this, yourActivityClass.class);
intent.putExtra("msg",messageBody);
person Rjz Satvara    schedule 06.12.2016

Я узнал ответ на свой вопрос. Когда я передаю значения с намерением, следует использовать

intent.setData

тогда он работает для нескольких уведомлений.

Это мой обновленный код для навигации по точному экрану.

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());
}

Здесь следует использовать эту строку для точной навигации по странице. это ошибка firebase. намерение.setData(новый Uri.Builder().схема(referenceKey).build()); Мы можем передать любую строку вместо referenceKey.

person AngelJanniee    schedule 07.12.2016