我正在使用聊天应用程序。我想在收到消息时显示自定义推送通知,在收到应用程序打开和关闭(未销毁或终止)通知时,以下代码工作正常,但是在奥利奥中未收到从后台取消或销毁应用程序的自定义推送通知及以上
这是我使用的代码
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
try {
context = getApplicationContext();
Map<String, String> data = remoteMessage.getData();
if ("message".equals(data.get("pushNotificationAction"))){
System.out.println("message");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(),
0, intent, 0);
String mediatype = data.get("mediaType");
String mesageType= data.get("messageType");
String channel_id = createNotificationChannel(getApplicationContext());
mBuilder = new NotificationCompat.Builder(getApplicationContext(),channel_id)
.setSmallIcon(R.drawable.kisan_smoll_logo1)
.setCustomBigContentView(contentViewBig)
.setCustomContentView(contentViewBig)
.setContentIntent(contentIntent)
.setContentTitle(data.get("messageText"))
.setWhen(when)
.setDefaults(Notification.DEFAULT_ALL)
.setPriority(NotificationManager.IMPORTANCE_MAX)
.setAutoCancel(true);
NotificationManager mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
mNotificationManager.notify(1, mBuilder.build());
}catch(Exception e){
e.printStackTrace();
}
从服务器发送JSON如下:
{
"message":{
"to": "FCMID",
"data" : {
"body" : "This is a Message!",
"title" : "Notifiation Message"
"mediaType":"IMAGE",
"messageType":"chat",
}
}
}
通过打开服务器时从服务器自定义Fcm推送通知发送数据,Android会收到,但是从最近通知中滑动应用程序却未收到