Failed to post notification on channel “null” Target Api is 26

前端 未结 8 764
盖世英雄少女心
盖世英雄少女心 2020-12-08 06:53

Two log showing

1: Use of stream types is deprecated for operations other than volume control

2: See the documentation of setSound() for what to use instea

相关标签:
8条回答
  • 2020-12-08 07:19

    This issue is related to the old FCM version.

    Update your dependency to com.google.firebase:firebase-messaging:15.0.2 or higher.

    This will fix the error

    failed to post notification on channel null
    

    when your app receives notifications in the background because now Firebase provides a default notification channel with basic settings.

    But you also can specify the default Notification Channel for FCM in the manifest.

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

    To learn more here

    0 讨论(0)
  • 2020-12-08 07:31

    First create the notification channel:

    public static final String NOTIFICATION_CHANNEL_ID = "4655";
    //Notification Channel
            CharSequence channelName = NOTIFICATION_CHANNEL_NAME;
            int importance = NotificationManager.IMPORTANCE_LOW;
            NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, NOTIFICATION_CHANNEL_NAME, importance);
            notificationChannel.enableLights(true);
            notificationChannel.setLightColor(Color.RED);
            notificationChannel.enableVibration(true);
            notificationChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
    
    
    NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
            notificationManager.createNotificationChannel(notificationChannel);
    

    then use the channel id in the constructor:

    final NotificationCompat.Builder builder = new NotificationCompat.Builder(context, NOTIFICATION_CHANNEL_ID)
                    .setDefaults(Notification.DEFAULT_ALL)
                    .setSmallIcon(R.drawable.ic_timers)
                    .setVibrate(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400})
                    .setSound(null)
                    .setContent(contentView)
                    .setPriority(NotificationCompat.PRIORITY_DEFAULT)
                    .setLargeIcon(picture)
                    .setTicker(sTimer)
                    .setContentIntent(timerListIntent)
                    .setAutoCancel(false);
    
    0 讨论(0)
提交回复
热议问题