Push-уведомление Firebase открывает активность без нажатия - PullRequest
0 голосов
/ 01 июня 2018

У меня проблема с push-уведомлениями Firebase.Вместо того, чтобы видеть уведомление, оно автоматически открывает действие, которое я поставил.Я хочу такое поведение, но после нажатия на уведомление.

Это мой код:

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    super.onMessageReceived(remoteMessage);

    final String title = remoteMessage.getData().get("title");
    final String message = remoteMessage.getData().get("body");

    showNotifications(title, message);
}

private void showNotifications(String title, String msg) {
    Intent i = new Intent(this, OrderDetailActivity.class);
    i.putExtra("order_id", 99);
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,
            i, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT);

    Notification notification = new NotificationCompat.Builder(this)
            .setContentText(msg)
            .setContentTitle(title)
            .setContentIntent(pendingIntent)
            .setSmallIcon(R.mipmap.ic_launcher_logo)
            .build();

    NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    manager.notify(NOTIFICATION_ID, notification);

    try {
        pendingIntent.send();
    } catch (PendingIntent.CanceledException e) {
        e.printStackTrace();
    }
}

1 Ответ

0 голосов
/ 01 июня 2018

На быстрый взгляд, мне интересно, зачем вам pendingIntent.send();?Из документов send () :

Выполните операцию, связанную с этим PendingIntent.

Вот почему, вероятно, выполняется присоединенное Intent,Попробуйте удалить эту строку.Подробнее см. Создание уведомления .

...