我有迁移gcm to fcm推送通知消息.但我如何从RemoteMessage获取捆绑数据收到onMesssageReceived方法.
Old GCM give bundle data onMessageReceiced method but in FCM there is RemoteMessage data.
Run Code Online (Sandbox Code Playgroud)
所以请告诉我如何解析remotemessage获取所有通知值.
我的PAYROL
{
"collapse_key":"score_update",
"priority":"high",
"content_available":true,
"time_to_live":108,
"delay_while_idle":true,
"data":
{
"message": "Message for new task",
"time": "6/27/2016 5:24:28 PM"
},
"notification": {
"sound": "simpleSound.wav",
"badge": "6",
"title": "Test app",
"icon": "myicon",
"body": "hello 6 app",
"notification_id" : "1140",
"notification_type" : 1,
"notification_message" : "TEST MESSAGE",
"notification_title" : "APP"
},
"registration_ids": ["cRz9SJ-gGuo:APA91bFJPX7_d07AR7zY6m9khQro81GmSX-7iXPUaHqqcOT0xNTVsOZ4M1aPtoVloLNq71-aWrMCpIDmX4NhMeDIc08txi6Vc1mht56MItuVDdA4VWrnN2iDwCE8k69-V8eUVeK5ISer"
]
}
Run Code Online (Sandbox Code Playgroud) java android android-notifications google-cloud-messaging firebase-cloud-messaging
我Firebase Cloud Messaging用来从我的服务器发送推送通知到我的Android应用程序.
当应用程序运行时,通知会堆叠,因为我将它们设置为我的组中的组FirebaseMessagingService.这很好.
但是,当应用程序未运行时,通知不会堆叠,并且每个通知都会单独显示.这不好.
即使应用程序未运行,如何确保通知堆叠?
这是我的FirebaseMessagingService样子:
public class MyFcmListenerService extends FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
RemoteMessage.Notification notification = remoteMessage.getNotification();
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.notif_white)
.setLargeIcon(BitmapFactory.decodeResource(getApplicationContext().getResources(), R.drawable.notif_white))
.setContentTitle(getResources().getString(R.string.app_name))
.setContentText(notification.getBody())
.setAutoCancel(true)
.setPriority(2)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent)
.setGroup("1")
.setGroupSummary(true)
.setOnlyAlertOnce(true);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0 , notificationBuilder.build());
}
}
Run Code Online (Sandbox Code Playgroud)