List of usage examples for android.bluetooth BluetoothAdapter isEnabled
@RequiresPermission(Manifest.permission.BLUETOOTH) public boolean isEnabled()
From source file:Main.java
/** * Enable bluetooth and get the adapter object * @return A BluetoothAdapter instance//from ww w . j av a2 s. co m */ public static BluetoothAdapter getLeAdapter(Activity _this) { // Initializes Bluetooth adapter. final BluetoothManager bluetoothLeManager = (BluetoothManager) _this .getSystemService(Context.BLUETOOTH_SERVICE); final BluetoothAdapter bluetoothLeAdapter = bluetoothLeManager.getAdapter(); // Ensures Bluetooth is available on the device and it is enabled. If not, // displays a dialog requesting user permission to mEnableCharacteristic Bluetooth. // TODO / FIXME currently this bugs if the user doesn't have BT enabled, // TODO / FIXME since it just returns null and doesn't check the result later. if (bluetoothLeAdapter == null || !bluetoothLeAdapter.isEnabled()) { Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); _this.startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT); return null; } else { return bluetoothLeAdapter; } }
From source file:Main.java
public static Pair<BluetoothManager, BluetoothAdapter> checkBT(final Activity activity) { // Use this check to determine whether BLE is supported on the device. Then // you can selectively disable BLE-related features. if (!btleSupport(activity)) { return null; }//from w ww . j a v a2 s . c o m final BluetoothManager bluetoothManager = (BluetoothManager) activity .getSystemService(Context.BLUETOOTH_SERVICE); BluetoothAdapter bluetoothAdapter = bluetoothManager.getAdapter(); //On some devices this does not work try { bluetoothAdapter.getBluetoothLeScanner(); } catch (NoSuchMethodError e) { return null; } // Ensures Bluetooth is available on the device and it is enabled. If not, // displays a dialog requesting user permission to enable Bluetooth. if (bluetoothAdapter == null || !bluetoothAdapter.isEnabled()) { Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); activity.startActivityForResult(enableBtIntent, 1); bluetoothAdapter = bluetoothManager.getAdapter(); } return new Pair<BluetoothManager, BluetoothAdapter>(bluetoothManager, bluetoothAdapter); }
From source file:com.coinblesk.client.utils.UIUtils.java
private static boolean isBluetoothEnabled(Context context) { BluetoothManager bm = (BluetoothManager) context.getSystemService(Context.BLUETOOTH_SERVICE); BluetoothAdapter mBluetoothAdapter = bm.getAdapter(); return mBluetoothAdapter != null && mBluetoothAdapter.isEnabled(); }
From source file:com.coinblesk.client.utils.UIUtils.java
private static void disableBluetooth(Activity activity) { BluetoothManager bm = (BluetoothManager) activity.getSystemService(Context.BLUETOOTH_SERVICE); BluetoothAdapter mBluetoothAdapter = bm.getAdapter(); if (mBluetoothAdapter != null && mBluetoothAdapter.isEnabled()) { mBluetoothAdapter.disable();//from www. j a va 2s . c o m Intent exchangeRateChanged = new Intent(Constants.EXCHANGE_RATE_CHANGED_ACTION); LocalBroadcastManager.getInstance(activity).sendBroadcast(exchangeRateChanged); } }
From source file:cordova.plugins.Diagnostic.java
public static boolean setBluetoothState(boolean enable) { BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); boolean isEnabled = bluetoothAdapter.isEnabled(); if (enable && !isEnabled) { return bluetoothAdapter.enable(); } else if (!enable && isEnabled) { return bluetoothAdapter.disable(); }//from w w w . j a v a2 s . co m return true; }
From source file:org.bcsphere.bluetooth.tools.Tools.java
public static boolean getBluetoothState() { BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); if (adapter.isEnabled()) { return true; } else {//from w ww . j a va 2 s. c om return false; } }
From source file:org.bcsphere.bluetooth.tools.Tools.java
static public boolean isOpenBluetooth() { BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (bluetoothAdapter.isEnabled()) { return true; } else {/*from w ww .j a v a 2 s . c o m*/ return false; } }
From source file:com.dipesan.miniatm.miniatm.services.BluetoothConnexionManager.java
private BluetoothConnexionManager() { BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); if (!adapter.isEnabled()) { adapter.enable(); } }
From source file:shantanu.housemate.bluetoothchat.BluetoothActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_bluetooth_main); //Disable bluetooth BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (mBluetoothAdapter.isEnabled()) { mBluetoothAdapter.disable();//from w w w.ja va2 s. com } Log.i("BLUETOOTH ACTIVITY", "STARTED"); if (savedInstanceState == null) { FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); fragment = new BluetoothChatFragment(); transaction.replace(R.id.sample_content_fragment, fragment); transaction.commit(); } }
From source file:com.djit.mixfader.sample.BaseActivity.java
/** * Handles permissions and features needed by the app *//*from ww w .j a va2s . co m*/ @Override protected void onResume() { super.onResume(); // Asks for Bluetooth activation is needed final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); final BluetoothAdapter bluetoothAdapter = bluetoothManager.getAdapter(); if (bluetoothAdapter == null || !bluetoothAdapter.isEnabled()) { final Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT); } // Asks for permissions if needed final int checkCoarseLocation = ContextCompat.checkSelfPermission(this, "android.permission.ACCESS_COARSE_LOCATION"); final int checkFineLocation = ContextCompat.checkSelfPermission(this, "android.permission.ACCESS_FINE_LOCATION"); if (checkCoarseLocation == PackageManager.PERMISSION_DENIED && checkFineLocation == PackageManager.PERMISSION_DENIED) { ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.ACCESS_COARSE_LOCATION }, MY_PERMISSIONS_REQUEST_COARSE_LOCATION); } else { // Ask for location service if needed if (needToEnableLocation(this)) { final Intent viewIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); startActivity(viewIntent); } } }