我正在测试我的应用程序,该应用程序使用 NotificationManager 发送振动通知。目前,我的 list 中没有振动权限。我了解拥有它的必要性,但在未经许可的情况下我发现设备之间存在一些奇怪的行为。
<uses-permission android:name="android.permission.VIBRATE"></uses-permission>
我主要在 Galaxy S4 上进行测试,它允许我进行振动,即使没有设置权限。它在 Android 4.3 上。我刚刚用三星 Galaxy Nexus 进行了测试,它在尝试振动时生成了运行时异常,表明我没有权限。 Nexus 运行在 Android 4.3 上。
我明白我应该有权限,但为什么S4似乎不在乎它没有权限?有没有可能S4 stock ROM真的不关心权限?
这是生成的内部异常,它的值(value):
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)
最佳答案
您应该包含此权限。
我在 Google Nexus 4 上测试没有问题,但我必须获得许可,因为其他型号如 HUAWEY 和 BQ 需要它。
关于android - 仅在某些设备上需要振动权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25567964/