简体   繁体   English

仅在某些设备上需要振动权限

[英]Vibrate permission required only on some devices

I'm testing my app that uses the NotificationManager to send up a notification which does a vibration. 我正在测试我的应用程序使用NotificationManager发送一个振动的通知。 Currently, I do not have the Vibrate permission in my manifest. 目前,我的清单中没有Vibrate权限。 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. 我主要测试一个Galaxy S4,它可以让我做振动,即使没有许可设置。 It's on Android 4.3. 这是在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. 我刚刚测试了三星Galaxy Nexus,它在尝试振动时产生了运行时异常,表明我没有获得许可。 The Nexus is on Android 4.3. Nexus适用于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? 我知道我应该获得许可,但为什么S4似乎并不关心它缺少许可? Is it possible that the S4 stock ROM really doesn't care about permissions? S4 stock ROM真的不关心权限吗?

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)

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. 我测试了谷歌Nexus 4没有问题,但我不得不提出许可,因为像HUAWEY和BQ等其他型号需要它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM