Android Oreo通知-通道不工作
我正在尝试在Oreo设备中使用Firebase消息,但即使正在创建通道,我也无法在正确的通道中接收数据。(注意:这在模拟器中不起作用,但仅在设备上起作用) 这是我的应用程序类:Android Oreo通知-通道不工作,android,firebase-cloud-messaging,Android,Firebase Cloud Messaging,我正在尝试在Oreo设备中使用Firebase消息,但即使正在创建通道,我也无法在正确的通道中接收数据。(注意:这在模拟器中不起作用,但仅在设备上起作用) 这是我的应用程序类: public class FCMPlayApp extends Application { @Override public void onCreate() { super.onCreate(); FirebaseMessaging.getInstance().subs
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"/>
你能告诉我我错过了什么吗。正如迭戈提到的:
android_channel_id应位于通知负载内
这就是答案。一旦迭戈回答了,我会把它标记为答案。这只是供其他人参考。您能从logcat提供更多日志吗?android\u channel\u id应该放在通知负载内。但仍然请分享更多日志,因为崩溃无论如何都不会发生。@Diegiorgini奇怪的是,当应用程序在前台时,我无法收到通知,并且应用程序正在按预期工作。但当它在后台崩溃,但没有日志,它只是停止。我将android_channel_id移动到了通知负载中,但仍然没有帮助。请检查您是否正在使用最新版本的SDK。你能用logcat检查日志并上传你在那里看到的内容吗?不使用android studio。只需运行“adb logcat-c”(清理旧日志)和“adb logcat”again@DiegoGiorgini应用程序在设备上运行良好,但在模拟器上则不然。不知道为什么会这样。我将修改我的问题,并要求您提供android_channel_id的答案,以便我将其标记为答案。
{
"to": "/topics/all",
"data": {
"msg_bg_color" : "#ABCDEF"
},
"notification": {
"body": "Hello",
"title": "This is test message."
},
"android_channel_id" : "channel_all"
}