如果Android应用想要访问蓝牙,是否必须明确要求用户切换蓝牙?用户是否可以授权应用程序在需要时将其打开(和关闭)?
答案 0 :(得分:2)
无需请求手动切换它,您只需要求权限也需要在android清单中添加权限
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH_PRIVILEGED" />
启用BT的代码
// enable device discovery - this will automatically enable Bluetooth
Intent discoveryIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
discoveryIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, DISCOVER_DURATION);
startActivityForResult(discoveryIntent, REQUEST_BLU);