【发布时间】:2019-11-26 06:55:19
【问题描述】:
在 android 中,FCM 通知来了,应用程序处于后台状态,当被点击时,它会重定向到默认活动 (LoginActivity),但我想导航到指定的活动 (HomeActivity)。
NotificationCompat.Builder notification = new NotificationCompat.Builder(this, "CHANNEL_1");
notification/*.setSound(soundUri)*/
.setSmallIcon(R.drawable.ic_photo_camera_black_24dp)
.setColor(getResources().getColor(R.color.colorAccent))
.setAutoCancel(true)
.setContentTitle(title)
.setContentText(message);
Intent intent = new Intent(this, HomeActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent,
0);
notification.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(1, notification.build());
【问题讨论】:
-
请发布一些代码以显示您所做的事情
-
此代码完美解决了您遇到的其他一些编码错误。
-
当我发送“notification json”时,它会在应用程序在后台时打开默认活动“通知”:{“body”:“Hello data”,“title”:“这是测试标题数据.", "message": "This is test message.data" } 当我发送 "data json" 时,它会在应用程序在后台时打开特定的活动 "data": { "body": "Hello data", "title ": "这是测试标题数据。", "message": "这是测试消息。数据" }
-
这段代码写在哪里?
标签: android