Ensure Bluetooth is turned on. - Android Bluetooth

Android examples for Bluetooth:Turn On bluetooth

Description

Ensure Bluetooth is turned on.

Demo Code

import android.bluetooth.BluetoothAdapter;

public class Main {
  /**/*w  ww. j a  v a2  s . com*/
   * Ensure Bluetooth is turned on.
   *
   * @throws IllegalStateException
   *           If {@code adapter} is null or Bluetooth state is not
   *           {@link BluetoothAdapter#STATE_ON}.
   */
  static void checkAdapterStateOn(BluetoothAdapter adapter) {
    if (adapter == null || adapter.getState() != BluetoothAdapter.STATE_ON) {
      throw new IllegalStateException("BT Adapter is not turned ON");
    }
  }
}

Related Tutorials