Cannot disable notification vibration in Android 8

前端 未结 5 904
失恋的感觉
失恋的感觉 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:30

    Add this line to your code to stop vibration:

    notificationChannel.enableVibration(false);
    // Above line will disable your vibration for the notification
    

    Also, remove the vibration pattern.

    So, your updated code will be:

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationChannel notificationChannel = new NotificationChannel(CHANNEL_ID, CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH);
        //setting pattern to disable vibrating
        notificationChannel.enableVibration(false);
    
        notificationBuilder = new NotificationCompat.Builder(ctx, CHANNEL_ID);
    } else {
        notificationBuilder = new NotificationCompat.Builder(ctx);
        notificationBuilder.setVibrate(new long[]{0L});
    }
    

提交回复
热议问题