0

Не получается получить Bandle из Notification

public class NotificationsService extends FirebaseMessagingService {

        Uri sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

        Intent intent = new Intent(this, MainActivity.class);
        intent.putExtra("notification", notificationModel);
        intent.setAction(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_LAUNCHER);

        intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOPIntent.FLAG_ACTIVITY_CLEAR_TOP);

        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
                .setContentTitle(map.get("alert"))
                .setContentText(map.get("alert"))
                .setSmallIcon(R.drawable.com_facebook_button_icon)
                .setAutoCancel(false)
                .setContentIntent(PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT))
                .setSound(sound);

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

        Notification notification = notificationBuilder.build();
        notification.flags = Notification.FLAG_AUTO_CANCEL;
        notificationManager.notify(0,notification);
    }

И MainActivity на который мы переходит по PendingIntent

    @Override
    protected void onResume() {
        super.onResume();
        Intent intent = getIntent();
        notificationModel = (NotificationModel) intent.getSerializableExtra("notification");
        if (notificationModel != null){
            App.showLog(notificationModel.toString());
        }
    }

И в notificationModel приходит null

1 ответ 1

0
    intent.putExtra("notification", notificationModel);

Чо такое notificationModel? Тут у нас точно не нулл?

    intent.addCategory(Intent.CATEGORY_LAUNCHER);

Зачем?

    intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOPIntent.FLAG_ACTIVITY_CLEAR_TOP);

Чоо???

5
  • Точно не null, флаги позволяют открывать уже созданные activity ну а категории(не обязательный параметр и возможно лишний) в данном случае позволяют открыть launch_activty
    – Heaven
    6 сен 2017 в 14:46
  • 2
    В уже созданном activity надо ловить onNewIntent - новый интент приходит только туда и автоматически не сохраняется, но Вы можете сохранить оттуда сами вызвав setIntent.
    – woesss
    6 сен 2017 в 14:58
  • Всё верно, помогло
    – Heaven
    6 сен 2017 в 15:13
  • Не является ответом на вопрос. Чтобы оставить свои замечания или попросить у автора внести уточнения, оставьте комментарий к соответствующему сообщению. - Из очереди проверок
    – kizoso
    7 сен 2017 в 9:58
  • @kizoso Зато является отличным пинком, который помог найти ответ на вопрос.
    – bukkojot
    7 сен 2017 в 15:14

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.