Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/203.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android API级别26+;上未显示通知;FCM升级后_Android_Firebase_Push Notification_Android Emulator_Firebase Cloud Messaging - Fatal编程技术网

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

Android API级别26+;上未显示通知;FCM升级后,android,firebase,push-notification,android-emulator,firebase-cloud-messaging,Android,Firebase,Push Notification,Android Emulator,Firebase Cloud Messaging,下面的代码似乎没有在我的模拟器上显示通知。我从弃用的Firebase代码升级到新的东西,带有通道。有什么我应该调查的吗 <application android:icon="@drawable/icon" android:allowBackup="false" android:label="@string/application_label" android:theme="@style/Theme"> <meta-data android:name="com.g

下面的代码似乎没有在我的模拟器上显示通知。我从弃用的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)为目标,并在未指定通知通道的情况下发布通知,则不会显示通知,系统会记录错误

阅读更多文档,请访问:


显然,您已经为通知使用了通知通道,但尚未创建与该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开发者端的说法

这不是我做的吗?@MikeFlynn你创建了频道吗?我知道了,我想在通知中添加频道名称就是了。让我试试。我这样做是为了显示对象中的值。来吧,伙计