/* 取得默认的蓝牙适配器 */
private BluetoothAdapter mBtAdapter = BluetoothAdapter.getDefaultAdapter();
//如果蓝牙未打开,打开蓝牙
if (!mBtAdapter.isEnabled()) {
Intent enableIntent = new Intent(
BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableIntent, 3);
}
//关闭蓝牙
mBtAdapter.disable();
private BluetoothAdapter mBtAdapter = BluetoothAdapter.getDefaultAdapter();
//如果蓝牙未打开,打开蓝牙
if (!mBtAdapter.isEnabled()) {
Intent enableIntent = new Intent(
BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableIntent, 3);
}
//关闭蓝牙
mBtAdapter.disable();
本文介绍了如何使用Java代码操作蓝牙设备,包括获取默认蓝牙适配器、检查蓝牙是否开启及如何开启和关闭蓝牙。
1481

被折叠的 条评论
为什么被折叠?



