Android examples for android.bluetooth:Bluetooth Enable
Determines if the device supports Bluetooth and whether it is currently enabled or not.
import android.app.Activity; import android.bluetooth.BluetoothAdapter; public class Main { /**//w w w . jav a2 s.com * 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 String getBTStatus(Activity activity) { BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (bluetoothAdapter == null) { // NFC is not supported on this phone return "BT_NOT_SUPPORTED"; } if (bluetoothAdapter.isEnabled()) { // adapter exists and is enabled. return "BT_ENABLED"; } else { return "BT_NOT_ENABLED"; } } }