我正在使用 Android 6.01 API 23 为智能 watch 开发应用程序。
我想添加一些振动功能。
我在 AndroidManifest.xml
中定义了以下内容:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="myexample.warehousehelper.mobile">
<uses-permission android:name="android.permission.VIBRATE"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
我收到以下异常
java.lang.RuntimeException: Unable to start activity ComponentInfo{myexample.warehousehelper/myexample.warehousehelper.wear.MainActivity}:
java.lang.SecurityException: Requires VIBRATE permission
“震动来电”如下:
Vibrator v = (Vibrator) getSystemService(VIBRATOR_SERVICE);
v.vibrate(200);
任何提示为什么会出现这种行为?
最佳答案
好吧,承认我发布了错误的 list 是非常痛苦的。我已将权限授予 mobile
版本,而不是 wear
版本。也就是说,我使用了错误的Manifest.xml
。
现在它可以正常工作,除了权限之外什么都不做。
感谢您的帮助。
关于java - 尽管权限在 list 中,但需要 VIBRATE 权限异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41695605/