Cannot disable notification vibration in Android 8

前端 未结 5 891
失恋的感觉
失恋的感觉 2021-02-14 18:54

I try to disable vibration when showing a notification.

Func:

public static Notification buildNotifForUploaderService(Context ctx, String          


        
5条回答
  •  名媛妹妹
    2021-02-14 19:18

    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);
        }
    }
    

提交回复
热议问题