有没有办法检查设备是否有蓝牙适配器? 我有一个没有蓝牙的平板电脑。那我该怎么处理呢?
答案 0 :(得分:10)
向Manifest添加权限
<manifest ... >
<uses-permission android:name="android.permission.BLUETOOTH" />
...
</manifest>
活动代码
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (bluetoothAdapter == null) {
//handle the case where device doesn't support Bluetooth
}
else
{
//bluetooth supported
}
答案 1 :(得分:3)
为了完整起见,我认为你也可以这样做:
getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)
我认为这是正常的蓝牙:
getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH)
不确定这是否比请求适配器更优化。
答案 2 :(得分:2)
您只需检查是否可以获得默认BluetoothAdapter
。
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (bluetoothAdapter == null) {
//handle the case where device doesn't support Bluetooth
}
else
{
//bluetooth supported
}
希望这有帮助。