java - 尽管权限在 list 中,但需要 VIBRATE 权限异常

标签 java android android-manifest android-vibration

我正在使用 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/

相关文章:

java - 我们应该在哪里保存我们的二进制测试数据?

android - SetPanLimits() 与轴 Achartengine 中的日期

android - 启动时启动 Activity

Java 计算器 android 应用程序在计算之前或之后的任何运算符强制关闭(需要异常处理帮助)

java - 从 javascript 调用 Java 时出现通信权限问题

java - 如何设置门户组件:resourceURL to output https URL?

Android 的 LocationManager 忽略 requestLocationUpdates 调用中的更改,但仅在 Droid 上

Android TalkBack EditText - 提示与 contentDescription

使用意图过滤器时 Flutter Android 12 安装错误

android - 无法收听 android wi-fi 管理器的状态?