List of usage examples for android.content Context BLUETOOTH_SERVICE
String BLUETOOTH_SERVICE
To view the source code for android.content Context BLUETOOTH_SERVICE.
Click Source Link
From source file:com.commontime.plugin.LocationManager.java
private void initBluetoothAdapter() { Activity activity = cordova.getActivity(); BluetoothManager bluetoothManager = (BluetoothManager) activity.getSystemService(Context.BLUETOOTH_SERVICE); bluetoothAdapter = bluetoothManager.getAdapter(); }
From source file:com.google.android.apps.forscience.ble.MyBleService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) { Intent newIntent = new Intent(BleEvents.BLE_UNSUPPORTED); LocalBroadcastManager.getInstance(this).sendBroadcast(newIntent); return START_NOT_STICKY; }/*from w ww . ja v a 2 s. com*/ if (bluetoothManager == null) { bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); } if (btAdapter == null) { btAdapter = bluetoothManager.getAdapter(); } if (!checkBleEnabled()) { return START_NOT_STICKY; } // Intent newIntent = new Intent(BleEvents.BLE_ENABLED); // LocalBroadcastManager.getInstance(this).sendBroadcast(newIntent); return START_STICKY; }
From source file:com.cqupt.pedometer.main.UartService.java
/** * ?? ?mBluetoothAdapter/* w w w. j a va 2s.c om*/ * Initializes a reference to the local Bluetooth adapter. * * @return Return true if the initialization is successful. */ public boolean initialize() { // For API level 18 and above, get a reference to BluetoothAdapter through // BluetoothManager. if (mBluetoothManager == null) { mBluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); if (mBluetoothManager == null) { return false; } } mBluetoothAdapter = mBluetoothManager.getAdapter(); if (mBluetoothAdapter == null) { return false; } return true; }
From source file:net.kenevans.android.blecardiacmonitor.BCMBleService.java
/** * Initializes a reference to the local Bluetooth adapter. * * @return Return true if the initialization is successful. *//* w w w . j av a2s .c o m*/ public boolean initialize() { Log.d(TAG, "initialize"); // For API level 18 and above, get a reference to BluetoothAdapter // through BluetoothManager. if (mBluetoothManager == null) { mBluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); if (mBluetoothManager == null) { Log.e(TAG, "Unable to initialize BluetoothManager"); return false; } } mBluetoothAdapter = mBluetoothManager.getAdapter(); if (mBluetoothAdapter == null) { Log.e(TAG, "Unable to obtain a BluetoothAdapter"); return false; } return true; }
From source file:com.buddi.client.dfu.DfuActivity.java
private boolean isBLEEnabled() { final BluetoothManager manager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); final BluetoothAdapter adapter = manager.getAdapter(); return adapter != null && adapter.isEnabled(); }
From source file:com.cypress.cysmart.CommonFragments.ProfileScanningFragment.java
private void checkBleSupportAndInitialize() { // Use this check to determine whether BLE is supported on the device. if (!getActivity().getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) { Toast.makeText(getActivity(), R.string.device_ble_not_supported, Toast.LENGTH_SHORT).show(); getActivity().finish();//from w w w . j av a2 s . c o m } // Initializes a Blue tooth adapter. final BluetoothManager bluetoothManager = (BluetoothManager) getActivity() .getSystemService(Context.BLUETOOTH_SERVICE); mBluetoothAdapter = bluetoothManager.getAdapter(); if (mBluetoothAdapter == null) { // Device does not support Blue tooth Toast.makeText(getActivity(), R.string.device_bluetooth_not_supported, Toast.LENGTH_SHORT).show(); getActivity().finish(); } }
From source file:com.ibm.pi.beacon.PIBeaconSensor.java
private void initBluetoothAdapter() throws Exception { if (mBluetoothAdapter == null) { final BluetoothManager bluetoothManager = (BluetoothManager) mContext .getSystemService(Context.BLUETOOTH_SERVICE); mBluetoothAdapter = bluetoothManager.getAdapter(); if (mBluetoothAdapter == null) throw new Exception("Failed to get bluetooth adapter"); }/* w w w . j a v a 2 s .c o m*/ }
From source file:net.jpuderer.android.bluedoor.DoorlockService.java
/** * Initializes a reference to the local Bluetooth adapter. * * @return Return true if the initialization is successful. *//*from w ww. ja va 2 s.c o m*/ public boolean initialize() { // For API level 18 and above, get a reference to BluetoothAdapter through // BluetoothManager. if (mBluetoothManager == null) { mBluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); if (mBluetoothManager == null) { Log.e(TAG, "Unable to initialize BluetoothManager."); return false; } } mBluetoothAdapter = mBluetoothManager.getAdapter(); if (mBluetoothAdapter == null) { Log.w(TAG, "Unable to obtain a BluetoothAdapter."); return false; } if (!mBluetoothAdapter.isEnabled()) { Log.i(TAG, "BluetoothAdapter is not enabled."); return false; } mBluetoothLeScanner = mBluetoothAdapter.getBluetoothLeScanner(); if (mBluetoothLeScanner == null) { Log.w(TAG, "Unable to obtain a BluetoothLeScanner."); return false; } return true; }
From source file:com.bluewatcher.activity.BlueWatcherActivity.java
private boolean isBluetoothEnabled() { final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); BluetoothAdapter bluetoothAdapter = bluetoothManager.getAdapter(); if (bluetoothAdapter == null) { Toast.makeText(this, R.string.error_bluetooth_not_supported, Toast.LENGTH_LONG).show(); finish();//from w w w . j a v a2s. co m } boolean enabled = true; if (!bluetoothAdapter.isEnabled()) { enabled = false; Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableBtIntent, ENABLE_BLUETOOTH); } return enabled; }
From source file:com.upnext.blekit.BLEKit.java
/** * Checks whether Bluetooth LE is available on the device and Bluetooth turned on. * * If BLE is not supported, then a dialog with appropriate message is shown. * If BLE is supported, but Bluetooth is not turned on then a dialog with message is shown and an option to go directly to settings and turn Bluetooth on. * * A good place to invoke this method would be onResume() in your Activity. * * @param activity Activity// ww w . j av a 2s .co m * @return false if BLE is not supported or Bluetooth not turned on; otherwise true */ public static boolean checkAvailability(Activity activity) { if (!activity.getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) { showErrorDialog(activity.getString(R.string.blekit_ble_unsupported), activity, true); } else { if (((BluetoothManager) activity.getSystemService(Context.BLUETOOTH_SERVICE)).getAdapter() .isEnabled()) { return true; } showErrorDialog(activity.getString(R.string.blekit_bt_not_on), activity, false); } return false; }