6

I'm testing my app that uses the NotificationManager to send up a notification which does a vibration. Currently, I do not have the Vibrate permission in my manifest. I understand the need to have it, but am seeing some weird behavior between devices without having the permission.

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

I mainly test on a Galaxy S4 which allows me to do the vibration, even without having the permission set. It's on Android 4.3. I just tested with a Samsung Galaxy Nexus which generated a Runtime exception when trying to do the vibrate, indicating I didn't have permission. The Nexus is on Android 4.3.

I understand that I should have the permission, but why is it that the S4 didn't seem to care that it lacked the permission? Is it possible that the S4 stock ROM really doesn't care about permissions?

Here was the inner exception generated, for what it's worth:

 Caused by: java.lang.SecurityException: Requires VIBRATE permission
        at android.os.Parcel.readException(Parcel.java:1431)
        at android.os.Parcel.readException(Parcel.java:1385)
        at android.app.INotificationManager$Stub$Proxy.enqueueNotificationWithTag(INotificationManager.java:320)
        at android.app.NotificationManager.notify(NotificationManager.java:136)
        at android.app.NotificationManager.notify(NotificationManager.java:109)
Stealth Rabbi
  • 10,156
  • 22
  • 100
  • 176

1 Answers1

6

You should include this permission.

I tested without problems for Google Nexus 4, but I had to put the permission because other models like HUAWEY and BQ needs it.

Martín Alcubierre
  • 4,341
  • 1
  • 27
  • 27
  • 1
    I just don't see why a phone manufacturer would override standard Android permission stuff like this. What is to be gained by doing this? – Stealth Rabbi Aug 29 '14 at 12:15
  • We should wrap our `NotificationManager` code in try-catch if we don't want to add vibrate permission. Check [this](http://stackoverflow.com/questions/13602190/java-lang-securityexception-requires-vibrate-permission-on-jelly-bean-4-2) for more info. Apparently it was some kind of bug in Android 4.2 – Bugs Happen Sep 22 '16 at 04:52