Android权限:需要蓝牙权限的应用程序崩溃

6

我最近正在创建一个使用蓝牙的应用程序。问题是每当我启动蓝牙服务时,我的应用程序会崩溃。以下是我的清单文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="in.petalappstudio.fit" >

<uses-permission android:name="ANDROID.PERMISSION.BLUETOOTH"/>
<uses-permission android:name="ANDROID.PERMISSION.BLUETOOTH_ADMIN"/>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <service
        android:name=".bluetoothManager"
        android:enabled="true"
        android:exported="true">
    </service>
</application>

现在,您可以看到我已经添加了蓝牙和蓝牙管理员的权限。

但是,我的应用程序崩溃了,在LOGCAT中显示的错误为:

"java.lang.RuntimeException: Unable to start service " and is caused by
"java.lang.SecurityException: Need BLUETOOTH ADMIN permission: Neither user 10145 nor current process has android.permission.BLUETOOTH_ADMIN."

但是如你所见,我已添加了权限。那么为什么会出现这种情况呢?
1个回答

4
尝试添加一个额外的权限:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

参考: Android权限BLUETOOTH清单错误

注意:还要使用以下方法检查设备是否支持蓝牙功能:

<uses-feature android:name="android.hardware.bluetooth" android:required="true" />

谢谢,没想到那样。 :) - Vivek Sasidharan
1
是的,我看到了并且也添加了。这很有帮助,谢谢 :) - Vivek Sasidharan

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接