我正在测试我的应用程序,它使用 NotificationManager 发送一个振动通知。目前,我的清单中没有振动权限。我了解拥有它的必要性,但在未经许可的情况下在设备之间看到了一些奇怪的行为。
<uses-permission android:name="android.permission.VIBRATE"></uses-permission>
我主要在 Galaxy S4 上进行测试,它允许我进行振动,即使没有设置权限。它在安卓 4.3 上。我刚刚用三星 Galaxy Nexus 进行了测试,它在尝试振动时产生了运行时异常,表明我没有权限。Nexus 在 Android 4.3 上。
我知道我应该有权限,但为什么 S4 似乎不在乎它缺乏权限?S4库存ROM是否真的不关心权限?
这是生成的内部异常,值得:
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)