我正在尝试在Oreo设备中使用Firebase消息,但即使正在创建频道,我也无法在正确的频道中接收数据。 (注意:这在模拟器中不起作用,但仅在设备上)
这是我的应用程序类:
public class FCMPlayApp extends Application {
@Override
public void onCreate() {
super.onCreate();
FirebaseMessaging.getInstance().subscribeToTopic(MessagingConstants.TOPIC_ALL);
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
createNotificationChannel();
}
}
@RequiresApi(Build.VERSION_CODES.O)
private void createNotificationChannel() {
NotificationChannel allChannel = new NotificationChannel(
"channel_all", "All Channel", NotificationManager.IMPORTANCE_HIGH);
((NotificationManager) getSystemService(NOTIFICATION_SERVICE))
.createNotificationChannel(allChannel);
}
}
这是我的消息服务类:
public class MessagingService extends FirebaseMessagingService {
private static final String TAG = "MessagingService";
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
Log.d(TAG, "Message received for topic: " + remoteMessage.getFrom());
}
}
以下是我在Android清单中为默认频道定义的内容:
<meta-data
android:name="com.google.firebase.messaging.default_notification_channel_id"
android:value="channel_all"/>
以下是我使用Postman工具发送推送消息的内容:
{
"to": "/topics/all",
"data": {
"msg_bg_color" : "#ABCDEF"
},
"notification": {
"body": "Hello",
"title": "This is test message."
},
"android_channel_id" : "channel_all"
}
请告诉我我错过的内容。
答案 0 :(得分:0)
正如迭戈所说:
android_channel_id应该进入通知有效载荷
这就是答案。一旦迭戈回答,我会将其标记为答案。这只是其他人的参考。