Firebase 数据通知无法点击
Posted
技术标签:
【中文标题】Firebase 数据通知无法点击【英文标题】:Firebase data notification cannot click 【发布时间】:2020-05-21 06:58:27 【问题描述】:您好,我想在通知中发送图像并使用数据通知 这是我的数据和 通知附带图片。但未点击通知 我如何发送可点击的?
""data"" : ""click_action"":"".MainActivity"",
""body"" : ""new Symulti update 22!"",
""title"" : ""new"",
""url"":""https://www.blablaaas.com"",
""img_url"":""https://www.image.com/image1""
""
【问题讨论】:
【参考方案1】:我希望您正在为 android 实现代码,因此要使通知可点击,您只需添加带有目标 Activity 名称的 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());
【讨论】:
我只是把这个 setetContentIntent(mainPIntent);非常感谢以上是关于Firebase 数据通知无法点击的主要内容,如果未能解决你的问题,请参考以下文章
如果应用程序未启动,Flutter Firebase 推送通知无法数据
如何在不点击通知的情况下从通知中获取数据(firebase 云消息传递和本机反应)