1.开启蓝牙
<uses-permission android:name="android.permission.BLUETOOTH"/> //使用蓝牙所需要的权限 <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/> //使用扫描和设置蓝牙的权限(申明这一个权限必须申明上面一个权限)
private BluetoothAdapter mBluetooth;
mBluetooth = BluetoothAdapter.getDefaultAdapter(); //获取Bluetooth适配器
if(!mBluetooth.isEnabled()) { mBluetooth.enable(); } Toast.makeText(MainActivity.this,"打开成功", Toast.LENGTH_SHORT).show();
if(mBluetooth.isEnabled()) { mBluetooth.disable(); } Toast.makeText(MainActivity.this,"关闭成功", Toast.LENGTH_SHORT).show();