public class BluetoothUtil { private BluetoothAdapter bluetoothAdapter; public BluetoothUtil() { // 获得蓝牙适配器对象 bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); } public boolean getBlueToothState() { // 获取蓝牙状态 return bluetoothAdapter.isEnabled(); } public boolean openBlueTooth() { if (getBlueToothState()) return true; // 打开蓝牙 return bluetoothAdapter.enable(); } public boolean colseBlueTooth() { if (!getBlueToothState()) return true; // 关闭蓝牙 return bluetoothAdapter.disable(); } // 调用系统的请求打开蓝牙 public void gotoSystem(Context context){ Intent intent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); context.startActivity(intent); } }
获取蓝牙开关状态以及开关蓝牙----苏苏的小弟子
最新推荐文章于 2024-07-18 01:36:53 发布