Android的FCM通知优先级被忽略



我正在测试android的fcm通知的优先级。然后用"正常"来测试优先级,"引起。

curl --location --request POST 'https://fcm.googleapis.com/fcm/send' 
--header 'Authorization: key=##############################' 
--header 'Content-Type: application/json' 
--data-raw '{
"to":"##########################",
"notification" : {
"sound" : "default",
"body" :  "high priority test",
"title" : "high priority test",
"content_available" : true,
"priority" : "high",
"time_to_live":4
}
}'

下面是我用来检查android应用程序中的推送通知优先级的代码片段。问题总是得到相同的优先级,即使我将优先级更改为"正常"。,"引起。

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
Log.d("msg", "onMessageReceived: " + remoteMessage.getData().get("message"));
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
String channelId = "Default";
NotificationCompat.Builder builder = new  NotificationCompat.Builder(this, channelId)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(remoteMessage.getNotification().getTitle())
.setContentText(remoteMessage.getNotification().getBody()
+" original priority-" + remoteMessage.getOriginalPriority()
+" delivered priority-" + remoteMessage.getPriority()
)
.setAutoCancel(true).setContentIntent(pendingIntent);;
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(channelId, "Default channel", NotificationManager.IMPORTANCE_DEFAULT);
manager.createNotificationChannel(channel);
}
manager.notify(0, builder.build());
}

我找到了答案,问题出在我放置"优先级"的地方。参数。它应该在通知对象之外。

curl --location --request POST 'https://fcm.googleapis.com/fcm/send' 
--header 'Authorization: key=##############' 
--header 'Content-Type: application/json' 
--data-raw '{
"to":"##############################",
"notification" : {
"sound" : "default",
"body" :  "high priority test11",
"title" : "high priority test11",
"content_available" : true,
"time_to_live":4
},
"priority" : "high"
}'

最新更新