Cannot disable notification vibration in Android 8

前端 未结 5 1469
野趣味
野趣味 2021-02-14 18:35

I try to disable vibration when showing a notification.

Func:

public static Notification buildNotifForUploaderService(Context ctx, String          


        
5条回答
  •  抹茶落季
    2021-02-14 19:30

    This function worked for me. With it I create the notification channel in what fully disable lights, vibration and sound.

    private void createNotificationChannel() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            NotificationChannel serviceChannel = new NotificationChannel(
                    CHANNEL_ID,
                    "Foreground Service Channel",
                    NotificationManager.IMPORTANCE_DEFAULT
            );
    
            serviceChannel.setVibrationPattern(new long[]{ 0 });
            serviceChannel.enableVibration(true);
            serviceChannel.enableLights(false);
            serviceChannel.setSound(null, null);
    
            NotificationManager manager = getSystemService(NotificationManager.class);
            manager.createNotificationChannel(serviceChannel);
        }
    }
    

提交回复
热议问题