Уведомление о данных Firebase не может нажать - PullRequest
0 голосов
/ 05 февраля 2020

Привет. Я хочу отправить изображение в уведомлении и использовать уведомление о данных. Это мои данные, и уведомление поставляется с изображением. но уведомление не нажимается Как я могу отправить clikable?

  ""data"" : {""click_action"":"".MainActivity"",
 ""body"" : ""new Symulti update 22!"", 
 ""title"" : ""new"", 
""url"":""https://www.blablaaas.com"",
""img_url"":""https://www.image.com/image1""
""}}

1 Ответ

0 голосов
/ 05 февраля 2020

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

 try {
        Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification);
        r.play();
    } catch (Exception e) {
        e.printStackTrace();
    }

    Intent mainIntent = new Intent(this, TabHostScreen.class);
    mainIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    PendingIntent mainPIntent = PendingIntent.getActivity(this, 0, mainIntent, PendingIntent.FLAG_ONE_SHOT);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID);
    builder.setSmallIcon(getNotificationIcon(builder));
    builder.setPriority(NotificationCompat.PRIORITY_DEFAULT);
    builder.setAutoCancel(true);
    //start intent on notification tap (MainActivity)
    builder.setContentIntent(mainPIntent);
    //custom style
    builder.setStyle(new NotificationCompat.DecoratedCustomViewStyle());
    builder.setCustomContentView(remoteCollapsedViews);
    //builder.setCustomBigContentView(remoteExpandedViews);
    long[] pattern = {500, 500, 500};
    builder.setVibrate(pattern);
    Random rand = new Random();
    NOTIFICATION_ID = rand.nextInt(1000);
    //notification manager
    NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(this);
    notificationManagerCompat.notify(NOTIFICATION_ID, builder.build());
...