set Bluetooth enable - Android android.bluetooth

Android examples for android.bluetooth:Bluetooth Enable

Description

set Bluetooth enable

Demo Code

import android.bluetooth.BluetoothAdapter;

public class Main{

    public static boolean setBluetooth(boolean enable) {
        BluetoothAdapter bluetoothAdapter = BluetoothAdapter
                .getDefaultAdapter();/*  w ww  .j a  v a  2s .  com*/
        boolean isEnabled = bluetoothAdapter.isEnabled();
        if (enable && !isEnabled) {
            return bluetoothAdapter.enable();
        } else if (!enable && isEnabled) {
            return bluetoothAdapter.disable();
        }
        return true;
    }

}

Related Tutorials