缺少BluetoothAdapter.isEnabled.BLUETOOTH所需的权限 [英] missing permissions required by BluetoothAdapter.isEnabled.BLUETOOTH

查看:1430
本文介绍了缺少BluetoothAdapter.isEnabled.BLUETOOTH所需的权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将蓝牙添加到我的应用程序,但是遇到以下问题.当我执行代码时:

I add bluetooth to my app but am running into the following problem. When I do the code:

BluetoothAdapter bluetoothAdapter=BluetoothAdapter.getDefaultAdapter();
if (bluetoothAdapter == null) {
    Toast.makeText(getApplicationContext(),"Device doesnt Support Bluetooth",Toast.LENGTH_SHORT).show();
}

if(!bluetoothAdapter.isEnabled()) {
    Intent enableAdapter = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
    startActivityForResult(enableAdapter, 0);
}

错误在以下行:

if(!bluetoothAdapter.isEnabled())

错误:

BluetoothAdapter.isEnabled所需的缺少权限:android.permissions.BLUETOOTH

Missing permissions required by BluetoothAdapter.isEnabled :android.permissions.BLUETOOTH

我向android清单文件添加了以下权限:

I added the following permissions to the android manifest file:

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

,但仍然遇到相同的问题.你知道我做错了吗?

but am still getting the same issue. Do you know what I did wrong?

推荐答案

  1. 由于使用权限,因此只需要<uses-permission>标记.您不需要<permissions>标记,因为这不是您的自定义权限.
  2. 也许您已将<uses-permission>标记放置在清单中错误的元素中,但是我不能用您提供的信息说其他话
  3. 由于您的bluetoothAdapter可以为null,因此可以添加到第二个IF空指针检查,或者在第一个IF中添加RETURN
  4. 具有<uses-feature>标签
  5. 也很好
  1. You only need <uses-permission> tag since you are using a permission. You don't need <permissions> tag since this is not your custom permission.
  2. Maybe you have placed <uses-permission> tag in the wrong element in manifest, but I cannot say anything else with the information you provided
  3. Since your bluetoothAdapter can be null, either add to second IF null pointer check, or add a RETURN in first IF
  4. It is also nice to have <uses-feature> tag

这篇关于缺少BluetoothAdapter.isEnabled.BLUETOOTH所需的权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆