0

當我通過Firebase控制檯發送沒有在Android Oreo上指定的渠道的通知時,必須使用「其他」渠道(如果從Android清單中提供了默認渠道)。所以我在我的應用程序中創建並提供默認頻道:Firebase消息傳遞:默認通知渠道不起作用

// Application onCreate 
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { 
    val manager = getSystemService(Context.NOTIFICATION_SERVICE) 
      as NotificationManager 
    val channelId = getString(R.string.notification_channel_id) 
    if(manager.getNotificationChannel(channelId)==null) { 
     val channel = NotificationChannel(channelId, 
       getString(R.string.notification_channel_name), 
       NotificationManager.IMPORTANCE_DEFAULT) 
     channel.description = 
       getString(R.string.notification_channel_description) 
     manager.createNotificationChannel(channel) 
    } 
} 

// Manifest 
<meta-data 
    android:name="com.google.firebase.messaging.default_notification_channel" 
    android:value="@string/notification_channel_id" /> 

但它不起作用。通知總是使用「雜項」頻道。我在這裏錯過了什麼,或者它是Firebase的錯誤?

回答

1

道歉,顯然文件沒有正確更新:(

在清單中正確的元數據是:

<meta-data 
    android:name="com.google.firebase.messaging.default_notification_channel_id" 
    android:value="@string/notification_channel_id" /> 

注意_idandroid:name屬性值的末尾

將獲得文檔更新儘快。

+0

現在,它的工作,謝謝。我交付PR修復quicksta rt-android回購。 –

+3

如何創建** notification_channel_id ** –

相關問題