Firebase数据通知无法单击

问题描述 投票:-2回答:1

[嗨,我想发送有关通知的图像并使用数据通知这是我的数据,通知带有图片。但未单击通知我该如何寄送好听的东西?

  ""data"" : {""click_action"":"".MainActivity"",
 ""body"" : ""new Symulti update 22!"", 
 ""title"" : ""new"", 
""url"":""https://www.blablaaas.com"",
""img_url"":""https://www.image.com/image1""
""}}
android firebase firebase-cloud-messaging firebase-notifications
1个回答
0
投票

我希望您正在为android实现代码,因此要使通知可点击,您只需添加带有目标活动名称的未决Intent,以便您获得可点击的操作。使用下面的代码作为参考。

 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());
© www.soinside.com 2019 - 2024. All rights reserved.