Example usage for android.bluetooth BluetoothAdapter getDefaultAdapter

List of usage examples for android.bluetooth BluetoothAdapter getDefaultAdapter

Introduction

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

Prototype

public static synchronized BluetoothAdapter getDefaultAdapter() 

Source Link

Document

Get a handle to the default local Bluetooth adapter.

Usage

From source file:Main.java

public static boolean isBtSearch() {
    BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    return mBluetoothAdapter.isDiscovering();
}

From source file:Main.java

public static void startBtSearch() {
    BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    mBluetoothAdapter.startDiscovery();
}

From source file:Main.java

public static @NonNull String getDeviceId() {
    BluetoothAdapter myDevice = BluetoothAdapter.getDefaultAdapter();
    String deviceName = myDevice.getName();
    return android.os.Build.BRAND + "-" + android.os.Build.MODEL + "-" + deviceName;
}

From source file:Main.java

public static void stopBluetooth() {
    BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    if (bluetoothAdapter.isEnabled()) {
        bluetoothAdapter.disable();/*from  www.  j  a v  a  2  s.  co  m*/
    }
}

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 o  m
    }
}

From source file:Main.java

public static String getPhoneName() {
    myDevice = BluetoothAdapter.getDefaultAdapter();
    String deviceName = myDevice.getName();
    Log.i("DEVICE_NAME : ", deviceName);
    return deviceName;
}

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 boolean isBluetoothEnabled(Context mContext) {
    BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
    if (adapter != null)
        return adapter.getState() == BluetoothAdapter.STATE_ON;
    return false;
}

From source file:Main.java

public static void toggleBlueTooth(Context context) {
    BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
    if (adapter != null) {
        switch (adapter.getState()) {
        case BluetoothAdapter.STATE_OFF:
            adapter.enable();/*from  ww w .  j  av a  2 s.co m*/
            break;
        case BluetoothAdapter.STATE_ON:
            adapter.disable();
            break;
        }
    }
}

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();
    }// w  w  w.j  a va 2  s. c  om
    // No need to change bluetooth state
    return true;
}