12

Sometimes I read that

notification.defaults|= Notification.DEFAULT_VIBRATE;

and

notification.defaults = Notification.DEFAULT_ALL;

requires the vibrate permission

<uses-permission android:name="android.permission.VIBRATE" ></uses-permission>

But sometimes I read that it doesn't.

Which one is the correct information?

Bugs Happen
  • 2,169
  • 4
  • 33
  • 59
Xander
  • 5,487
  • 14
  • 49
  • 77
  • 3
    Yes it does require the vibrate permission. Without the permission the app won't run! – Parth Doshi Oct 31 '12 at 13:47
  • 1
    Yes permission is needed – Sumant Oct 31 '12 at 13:47
  • 1
    Yes You have to specify permission – Arshad Ali Oct 31 '12 at 13:59
  • 2
    Interestingly I could run this (using DEFAULT_ALL) on one device (Nexus 4 running 4.2) without requesting the VIBRATE permission, but it would crash on another (Nexus S running 4.1). – Divisible by Zero Dec 17 '13 at 11:38
  • 1
    Same here, HTC ONE X with 4.2 didn't need the permission – pomber Nov 25 '14 at 15:38
  • 1
    I bet they've changed it in 4.2 then. I can understand why they would change that though. I mean, why would you need permission to do something the user has set as default? – Xander Dec 05 '14 at 19:04
  • 1
    I experienced a similar funny behaviour: I was showing notifications in the App with `Notification.DEFAULT_VIBRATE` with no problems on all devices *until* I added permissions for push notifications support. As soon as I added that, I was getting crashes because I did not include the `VIBRATE` permission on devices pre 4.2 (so only 4.0.X - 4.1.X). – Stefan Anca Feb 06 '15 at 10:25
  • 1
    Permissions for push notifications? I'm using push notifications in my app without a permission and it doesn't give me any errors – Xander Feb 15 '15 at 18:23
  • I've tested it on my Nexus 4 on lollipop, it do not need this permission. – GhostFlying Feb 23 '15 at 09:26
  • See also https://stackoverflow.com/questions/13602190/java-lang-securityexception-requires-vibrate-permission-on-jelly-bean-4-2 – caw Mar 15 '21 at 06:11

2 Answers2

9

Ok, apparently, you do need the vibrate permission. Thanks!

Xander
  • 5,487
  • 14
  • 49
  • 77
  • Yes, see the docs: https://developer.android.com/reference/kotlin/android/app/Notification#default_vibrate – emersion Sep 07 '22 at 08:55
7

You may be interested in reading: https://android.googlesource.com/platform/frameworks/base/+/cc2e849

As of 4.2.1:

Notification vibration improvements: [DO NOT MERGE]

  • When notifications vibrate as a fallback (that is, because they want to play a sound but the device is in vibrate mode), this no longer requires the VIBRATE permission.
  • As a bonus, if your notifications use DEFAULT_VIBRATE, you don't need the VIBRATE permission either.
  • If you specify a custom vibration pattern, you'll still need the VIBRATE permission for that.
  • Notifications vibrating in fallback mode use same vibration pattern but can be changed easily in future.
  • The DEFAULT_VIBRATE and fallback vibrate patterns are now specified in config.xml.
Mike Lambert
  • 1,976
  • 1
  • 17
  • 31