当应用程序处于后台/前景/已终止状态时,我会收到推送通知,但是当点击通知时,会发生以下情况,
活动被打开 前景/背景
该应用被杀死
该代码不适用于任何设备(中文和非中文设备以及Oreo及以下Oreo设备)。我已经检查了SO中所有重复的答案,但是没有用。
我在这里想念什么?任何帮助都会很棒。预先感谢。
我在php脚本中有以下代码
$msg = array
(
'body' => $_REQUEST['message'],
'title' => $_REQUEST['title'],
'click_action' => ('.Activity.SplashActivity'),
);
$fields = array
(
'to' => $_REQUEST['token'],
'notification' => $msg ,
'data'=>$msg,
);
以下代码位于AndroidManifest.xml文件中,
<activity android:name=".Activity.SplashActivity">
<intent-filter>
<action android:name="android.intent.action.SPLASHACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
以下是通知代码,
private void sendNotification(RemoteMessage remoteMessage) {
Log.e("remoteMessage foreground", remoteMessage.getData().toString());
String title = remoteMessage.getNotification().getTitle();
String body = remoteMessage.getNotification().getBody();
Intent resultIntent = new Intent(getApplicationContext() , IntroSplashActivity.class);
resultIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(),
0 /* Request code */, resultIntent,
PendingIntent.FLAG_ONE_SHOT);
NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(getApplicationContext(), CHANNEL_ID);
notificationBuilder.setAutoCancel(true)
.setDefaults(Notification.DEFAULT_ALL)
.setWhen(System.currentTimeMillis())
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.account_icon))
.setSmallIcon(R.drawable.account_icon)
.setBadgeIconType(NotificationCompat.BADGE_ICON_SMALL)
.setNumber(10)
.setTicker("Bestmarts")
.setContentTitle(title)
.setContentText(body)
.setContentIntent(pendingIntent)
.setContentInfo("Info");
notificationManager.notify(1, notificationBuilder.build());