1. Turn on Bluetooth
<uses-permission android:name="android.permission.BLUETOOTH"/> //The permissions required to use Bluetooth <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/> //Use the permission to scan and set Bluetooth (declaring this permission must declare the above permission)
private BluetoothAdapter mBluetooth;
mBluetooth = BluetoothAdapter.getDefaultAdapter(); //Get the Bluetooth adapter
if(!mBluetooth.isEnabled()) { mBluetooth.enable(); } Toast.makeText(MainActivity.this,"Open successfully", Toast.LENGTH_SHORT).show();
if(mBluetooth.isEnabled()) { mBluetooth.disable(); } Toast.makeText(MainActivity.this,"closed successfully", Toast.LENGTH_SHORT).show();