Android: Does Notification.DEFAULT_VIBRATE require vibrate permission?
Asked Answered
D

2

13

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?

Derrek answered 31/10, 2012 at 13:43 Comment(10)
Yes it does require the vibrate permission. Without the permission the app won't run!Fibrosis
Yes permission is neededValuer
Yes You have to specify permissionAbsinthism
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).Hatred
Same here, HTC ONE X with 4.2 didn't need the permissionPedi
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?Derrek
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).Luvenialuwana
Permissions for push notifications? I'm using push notifications in my app without a permission and it doesn't give me any errorsDerrek
I've tested it on my Nexus 4 on lollipop, it do not need this permission.Overmeasure
See also #13602690Bryonbryony
D
10

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

Derrek answered 31/10, 2012 at 14:8 Comment(1)
Yes, see the docs: developer.android.com/reference/kotlin/android/app/…Arms
L
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.
Lethargy answered 5/10, 2016 at 8:45 Comment(2)
much better answer then just answer "yes" (as in accepted answer), but usually we don't need this permission, so the actual answer is "no"Merengue
But isn't the actual answer "it depends on your android version"?Lethargy

© 2022 - 2025 — McMap. All rights reserved.