Some Oreo devices are not getting Push Notification

前端 未结 6 1381
没有蜡笔的小新
没有蜡笔的小新 2020-12-02 21:13

Samsung S8/S5/J2/Note3 are getting Firebase Push Notification successfully either app is killed, in background or foreground,

but In

6条回答
  •  春和景丽
    2020-12-02 22:08

    Since oreo there is new Notification Channels implementation (started in Android 8.0 (API level 26))

    so you have to create the channel using below code

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                CharSequence name = "News Channel";
                String description = "Default Notification News Channel";
                int importance = NotificationManager.IMPORTANCE_DEFAULT;
                NotificationChannel channel = new NotificationChannel(CHANNEL_ID, name, importance);
                channel.setDescription(description);
                NotificationManager notificationManager = getAppContext().getSystemService(NotificationManager.class);
                notificationManager.createNotificationChannel(channel);
            }
    

    and override notification builder as below

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getAppContext(),CHANNEL_ID);
    

    assuming you have CHANNEL_ID value something you want

    String CHANNEL_ID = "DEFAULT_NEWS_CHANNEL";
    

    this is already tested with OnePlus3T device so it should work for you

提交回复
热议问题