Example usage for android.bluetooth BluetoothAdapter enable

List of usage examples for android.bluetooth BluetoothAdapter enable

Introduction

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

Prototype

@RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN)
public boolean enable() 

Source Link

Document

Turn on the local Bluetooth adapter—do not use without explicit user action to turn on Bluetooth.

Usage

From source file:Main.java

public static void openBt() {
    BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    mBluetoothAdapter.enable();
}

From source file:Main.java

public static boolean operation(boolean isOpen) {
    BluetoothAdapter blueAdapter = BluetoothAdapter.getDefaultAdapter();
    if (isOpen) {
        return blueAdapter.enable();
    } else {//from  w w  w .jav  a  2  s  . co  m
        return blueAdapter.disable();
    }

}

From source file:Main.java

public static void startBluetooth() {
    BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    if (!bluetoothAdapter.isEnabled()) {
        bluetoothAdapter.enable();
    }/*from  w w  w  . j  a  v a  2 s. c om*/
}

From source file:Main.java

public static void onBluetooth() {
    BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    if (!bluetoothAdapter.isEnabled()) {
        bluetoothAdapter.enable();
        Log.i("Log", "Bluetooth is Enabled");
    }//from  w w  w . j av  a  2  s .  c  om
}

From source file:Main.java

private static void setBluetooth(int btVal) {
    BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    if (btVal == 0 && !bluetoothAdapter.isEnabled()) {
        bluetoothAdapter.enable();
    } else if (btVal == 1 && bluetoothAdapter.isEnabled()) {
        bluetoothAdapter.disable();//  www . j a  v a2s  . c o m
    }
}

From source file:Main.java

public static void enableBluetooth() {
    BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    if (bluetoothAdapter != null && !bluetoothAdapter.isEnabled()) {
        bluetoothAdapter.enable();
    }//from  ww w .j a  v a 2s  .  com
}

From source file:Main.java

public static void startBluetooth() {
    BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    if (bluetoothAdapter != null) {
        if (!bluetoothAdapter.isEnabled()) {
            bluetoothAdapter.enable();
        }/*from  w w  w  . j  a  v  a 2s .  com*/
    }
}

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  va  2  s .c  o  m
    // No need to change bluetooth state
    return true;
}

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   www. j a v  a2  s  .c o m
    }
    return adapter.getState() == BluetoothAdapter.STATE_ON;
}

From source file:Main.java

public static boolean enableBluetooth(boolean bEnable) {
    BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
    if (btAdapter == null) {
        // Bluetooth not supported
        return false;
    }//www.j a  v  a2 s . co m

    return bEnable ? btAdapter.enable() : btAdapter.disable();
}