【问题标题】:Requires VIBRATE permission Exception although Permission is in Manifest尽管权限在清单中,但需要 VIBRATE 权限异常
【发布时间】:2017-06-01 10:13:13
【问题描述】:

我正在使用 Android 6.01 API 23 为智能手表开发应用程序。 我想添加一些振动功能。 我在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);

任何提示为什么会出现这种行为?

【问题讨论】:

标签: java android android-manifest android-vibration


【解决方案1】:

好吧,承认我发布了错误的清单是非常痛苦的。我已授予mobile 版本而不是wear 版本的权限。也就是我用错了Manifest.xml

现在它可以正常工作,除了权限之外什么都不做。

感谢您的帮助。

【讨论】:

    猜你喜欢
    • 2018-07-17
    • 1970-01-01
    • 2012-11-16
    • 2022-01-02
    • 1970-01-01
    • 1970-01-01
    • 2016-01-23
    • 1970-01-01
    • 2021-02-28
    相关资源
    最近更新 更多