android - 当应用程序被用户或后台应用程序杀死时,活动未启动单击 FCM 推送通知
问题描述
我正在设置 FCM 推送通知,当我杀死应用程序或后台应用程序并生成通知时,当我单击通知时生成通知,然后应用程序未打开,Firebase 也没有给出任何日志错误。
通知通过 rest api post 请求生成到 firebase 后端。
我还通过 FCM Notification Quick Project 检查了同样的问题。
注意:-> 默认情况下,用户点击通知会打开应用程序启动器。一旦默认活动打开,这将不起作用,然后我将从系统托盘获取数据。
https://github.com/firebase/quickstart-android/issues/765
https://firebase.google.com/docs/cloud-messaging/android/receive#backgrounded
解决方案
private NotificationManager mNotificationManager;
private static int NOTIFICATION_ID = 0;
private void sendNotification(String msg) {
PendingIntent contentIntent = null;
mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
this).setSmallIcon(R.mipmap.ic_launcher)
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
.setContentTitle("Title")
.setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
.setContentText(msg);
mBuilder.setContentIntent(contentIntent);
mBuilder.setAutoCancel(true);
Random random = new Random();
NOTIFICATION_ID = random.nextInt(9999 - 1000) + 1000;
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}
推荐阅读
- javascript - javascript中的strassen矩阵乘法算法实现
- c - C 语言,为什么我们使用 envp[i] != 0 而不是 '\0';
- javascript - svelte 中的 API 请求
- outlook - Outlook 在启动时忽略加载项的 HKEY_LOCAL_MACHINE 条目
- swift - 返回 String 的 metadata?.downloadURL().absoluteString 更新
- javascript - 在javascript中调用同一文件中的函数
- c# - 组合来自不同对象的 JSON 字符串值
- c# - C#,EF 6 - DBContext 未打开连接
- python - 如何在 Python、Flask 中制作日期过滤栏?
- python-3.x - 比较两个变量python 3时收到类型错误