如何设置Android蓝牙权限

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3400245/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 10:02:01  来源:igfitidea点击:

How to set permissions for Android Bluetooth

androidpermissionsbluetoothmanifest

提问by Jon Mills

I'm new to Android development. I'm trying to get a simple HelloWorld app going on my (rooted) phone - and the app is trying to enable Bluetooth.

我是 Android 开发的新手。我正在尝试在我的(root 用户)手机上运行一个简单的 HelloWorld 应用程序 - 该应用程序正在尝试启用蓝牙。

I've set the Bluetooth permissions in my manifest is as follows, but I'm getting a Permission Denial exception when I try to run the application on my phone via Eclipse:

我在清单中设置了蓝牙权限,如下所示,但是当我尝试通过 Eclipse 在我的手机上运行应用程序时,我收到了权限拒绝异常:

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.example.helloandroid"
          android:versionCode="1"
          android:versionName="1.0">      
        <application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true" android:permission="android.permission.BLUETOOTH_ADMIN">
            <activity android:name=".HelloAndroid"
                      android:label="@string/app_name">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
        </application>


<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-sdk android:targetSdkVersion="7" android:minSdkVersion="5"></uses-sdk>
</manifest>

Is there something obvious I'm missing?

有什么明显的我遗漏了吗?

采纳答案by Jon Mills

I'm not quite sure what the problem was here.

我不太确定这里的问题是什么。

All I can say is that I reinstalled Eclipse and its plugins and now everything is working fine. Thanks for your help Mayra - I'll up-mark your answer because of your helpful and friendly approach.

我只能说我重新安装了 Eclipse 及其插件,现在一切正常。感谢您的帮助 Mayra - 由于您的帮助和友好的方法,我会提高您的答案。

回答by Julian Wise

The answer about what to include in your manifest.xml for bluetooth activity includes

关于蓝牙活动在 manifest.xml 中包含的内容的答案包括

<uses-feature android:name="android.hardware.bluetooth" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

The first three are of greater priority and as I'm sure you're aware there are different cases when each dependency may be required. Hope it helps with your setup!

前三个优先级更高,我相信您知道可能需要每个依赖项的情况不同。希望它对您的设置有所帮助!

回答by Cheryl Simon

The element types in the manifest are ordered. I think the uses-permission needs to be first under the tag.

清单中的元素类型是有序的。我认为使用权限需要首先在标签下。