8

i create notification channel to show notification in android 8.0 as below

 NotificationChannel uploadChannel = new NotificationChannel(Constants.NOTIFICATION_CHANNEL_UPLOAD_ID,"Uploads", NotificationManager.IMPORTANCE_LOW);
 uploadChannel.enableLights(false);
 uploadChannel.setDescription("Uploads Channel");
 notificationManager.createNotificationChannel(uploadChannel);

each time i show notification the phone vibrate many times. i disable vibrate from notification channel as below

uploadChannel.enableVibration(false);

i create notification as below

 NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context, Constants.NOTIFICATION_CHANNEL_UPLOAD_ID);

but it is not working phone is vibrating with each notification.

Manish
  • 1,071
  • 2
  • 10
  • 27

5 Answers5

24

In addition to Ahmadul Hoq's answer, which did work for me, I would like to add that you may need to remove the app and reinstall it before the vibration changes take place. The channel keeps its initial settings and stays alive if the app is killed - so changes may not be applied if you simply build and run.

  • Does this mean that we can no longer give the user the option to change notification vibration settings? I wonder how Whatsapp is doing it? – behelit Nov 14 '18 at 20:30
  • @behelit Developers are very likely to apply Admadul's changes, run the app and test the outcome. In this specific case, the changes do not apply directly which is confusing during development. I'm fairly sure you could also reboot the device and have a similar effect. I don't think this means users can't change notification vibration settings anymore. – Roland van der Linden Nov 15 '18 at 13:16
  • 4
    Alternatively, you can just **Clear App Data** – Kathir Dec 29 '18 at 17:31
  • 2
    If you want to apply changes made to a notification channel on production and to users that currently have your app installed, change your channel id to a new one. – Mostafa Arian Nejad Mar 04 '20 at 06:40
23

This is a bug on Android 8 notification system. I've tinkered with different combinations of enableVibration with setVibrationPattern(null) but it does not work.

Only solution that stops the vibration for me is this:

mNotificationChannel.setVibrationPattern(new long[]{ 0 });
mNotificationChannel.enableVibration(true);

FYI, even if I set a vibration pattern with 0, but set enableVibration to false, it vibrates.

Ahmadul Hoq
  • 705
  • 5
  • 14
  • 4
    if it doesn't work refer to [Roland van der Linden's Answer](https://stackoverflow.com/questions/46402510/notification-vibrate-issue-for-android-8-0/51289889#51289889) – Poorya Aug 16 '18 at 06:50
  • 1
    Did they fix it? Will this hack be working till the next "P" version? – Kirill Reznikov Aug 30 '18 at 18:33
  • 1
    @KirillReznikov Just tested on Android 9 and this hack still works, and they haven't fixed it yet.. – Ahmadul Hoq Sep 03 '18 at 06:46
2

I was initially using NotificationManager.IMPORTANCE_DEFAULT and could not get the vibrating to stop. Using NotificationManager.IMPORTANCE_LOW instead resolved the issue. NotificationManager.IMPORTANCE_MIN would also work; see here: https://developer.android.com/training/notify-user/channels#importance

mike47
  • 2,217
  • 1
  • 27
  • 50
2

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

add notificationChannel.setVibrationPattern(new long[]{ 0L }); uninstall the application or clear App Data. run it again It will work! reason: channel_id already registered for application.

Fakhar
  • 3,946
  • 39
  • 35