繁体   English   中英

FCM升级后,通知未显示在Android API级别26+上

[英]Notification not showing on Android API level 26+ after FCM upgrade

下面的代码似乎没有在我的模拟器上显示通知。 我将不赞成使用的Firebase代码升级为带有频道的新内容。 我有什么需要研究的吗?

<application android:icon="@drawable/icon" android:allowBackup="false" android:label="@string/application_label" android:theme="@style/Theme">
        <meta-data android:name="com.google.firebase.messaging.default_notification_icon" android:resource="@drawable/icon" />
        <meta-data android:name="com.google.firebase.messaging.default_notification_color" android:resource="@color/accentColor" />
        <meta-data android:name="com.google.firebase.messaging.default_notification_channel_id" android:value="@string/default_notification_channel_id" />
        ......
        <service
            android:name="com.exposure.services.ExposureFirebaseMessagingService">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT"/>
            </intent-filter>
        </service>
    </application>

在此处输入图片说明

在Android Oreo中,您必须使用渠道来创建通知。

从Android 8.0(API级别26)开始,必须将所有通知分配给一个频道。 对于每个渠道,您可以设置应用于该渠道中所有通知的视觉和听觉行为。 然后,用户可以更改这些设置,并确定您应用中的哪些通知渠道应该是侵入性的或根本不可见的。


注意:如果您以Android 8.0(API级别26)为目标并发布通知而未指定通知渠道,则不会出现该通知,并且系统会记录错误。

在以下网址阅读更多文档: https//developer.android.com/training/notify-user/channels


显然,您已使用通知通道进行通知,但尚未创建与该ID关联的通知通道。 因此,您需要在创建通知之前创建一个通知通道。

下面给出了创建通知通道的示例(可能在FCM服务类中):

@Override
public void onCreate() {
    super.onCreate();
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
        // Make sure you use the same channel id ("default" in this case)
        // while creating notifications.
        NotificationChannel channel = new NotificationChannel("default", "Default Channel",
                NotificationManager.IMPORTANCE_HIGH);
        channel.setDescription("Default Notification Channel");
        NotificationManager notificationManager = (NotificationManager)
                getSystemService(NOTIFICATION_SERVICE);
        if (notificationManager != null) {
            notificationManager.createNotificationChannel(channel);
        }
    }
}

在根据Google开发者方https://developer.android.com/training/notify-user/channels创建通知之前,请使用通知频道

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM