Example usage for android.bluetooth BluetoothAdapter isEnabled

List of usage examples for android.bluetooth BluetoothAdapter isEnabled

Introduction

In this page you can find the example usage for android.bluetooth BluetoothAdapter isEnabled.

Prototype

@RequiresPermission(Manifest.permission.BLUETOOTH)
public boolean isEnabled() 

Source Link

Document

Return true if Bluetooth is currently enabled and ready for use.

Usage

From source file:Main.java

public static boolean isBluetoothAvailable() {
    BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
    if (!adapter.isEnabled()) {
        if (adapter.getState() == BluetoothAdapter.STATE_OFF) {
            adapter.enable();//from w  w w . java2  s .  c om
        }
    }
    return adapter.getState() == BluetoothAdapter.STATE_ON;
}

From source file:Main.java

/**
 * Check if Bluetooth is on.//from  w w w . j  a v  a2 s.  com
 *
 * @param activity the activity
 * @return true, if successful
 */
public static boolean checkBLEOn(Activity activity) {
    BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
    return adapter.isEnabled();
}

From source file:Main.java

private static void setBluetooth(int btVal) {
    BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    if (btVal == 0 && !bluetoothAdapter.isEnabled()) {
        bluetoothAdapter.enable();//from   w w  w . j  a  v  a2 s . co  m
    } else if (btVal == 1 && bluetoothAdapter.isEnabled()) {
        bluetoothAdapter.disable();
    }
}

From source file:Main.java

/**
 * Checks if the bluetooth adapter is on and ready.
 */// ww w.  j  a  va  2  s  .  co  m
public static boolean isBluetoothAvailable() {
    BluetoothAdapter tempBtAdapter = BluetoothAdapter.getDefaultAdapter();
    return tempBtAdapter != null && tempBtAdapter.isEnabled();
}

From source file:Main.java

public static boolean isBluetoothOn() {
    BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    return bluetoothAdapter != null && bluetoothAdapter.isEnabled();
}

From source file:Main.java

public static void disableBluetooth() {
    BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    if (bluetoothAdapter != null && bluetoothAdapter.isEnabled()) {
        bluetoothAdapter.disable();/*w  ww  .j  a  v a  2 s  . co m*/
    }
}

From source file:Main.java

public static boolean setBluetooth(boolean enable) {
    BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    boolean isEnabled = bluetoothAdapter.isEnabled();
    if (enable && !isEnabled) {
        return bluetoothAdapter.enable();
    } else if (!enable && isEnabled) {
        return bluetoothAdapter.disable();
    }//from  ww w. j  a  va2  s .c  o m
    // No need to change bluetooth state
    return true;
}

From source file:Main.java

public static void enableBluetooth() {
    BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    if (bluetoothAdapter != null && !bluetoothAdapter.isEnabled()) {
        bluetoothAdapter.enable();/*from www .  ja  va2  s .c  o  m*/
    }
}

From source file:Main.java

public static boolean isBluetoothEnable() {
    BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    return bluetoothAdapter == null ? false : bluetoothAdapter.isEnabled();
}

From source file:Main.java

public static void stopBluetooth() {
    BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    if (bluetoothAdapter != null) {
        if (bluetoothAdapter.isEnabled()) {
            bluetoothAdapter.disable();//w w w.  ja v  a2 s. c o m
        }
    }
}