Determines if the device supports Bluetooth and whether it is currently enabled or not. - Android Bluetooth

Android examples for Bluetooth:Turn On bluetooth

Description

Determines if the device supports Bluetooth and whether it is currently enabled or not.

Demo Code


import android.app.Activity;
import android.bluetooth.BluetoothAdapter;

public class Main {
  /**/*from  w  w w . j a  v  a2  s  .  co m*/
   * Determines if the device supports Bluetooth and whether it is currently
   * enabled or not.
   * 
   * @param activity
   *          - that calls this method
   * @return {@link at.gv.egiz.android.bluetooth.BluetoothConstants #BT_NOT_SUPPORTED}
   *         if device does not have NFC support.
   *         {@link at.gv.egiz.android.bluetooth.BluetoothConstants #BT_NOT_ENABLED}
   *         if NFC is not enabled by the user, otherwise
   *         {@link at.gv.egiz.android.bluetooth.BluetoothConstants #BT_ENABLED}
   */
  public static int getBTStatus(Activity activity) {
    BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

    if (bluetoothAdapter == null) {
      // NFC is not supported on this phone
      return -1;
    }
    if (bluetoothAdapter.isEnabled()) {
      // adapter exists and is enabled.
      return 1;
    } else {
      return 2;
    }

  }
}

Related Tutorials