List of usage examples for android.bluetooth BluetoothAdapter startLeScan
@Deprecated @RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN) public boolean startLeScan(LeScanCallback callback)
From source file:com.mooshim.mooshimeter.main.ScanActivity.java
public synchronized void startScan() { if (mScanOngoing) return;/*from www . j a v a 2 s.co m*/ mScanOngoing = true; final Handler h = new Handler(); mBtnScan.setEnabled(false); updateScanningButton(false); // Prune disconnected meters List<MooshimeterDevice> remove = new ArrayList<MooshimeterDevice>(); for (MooshimeterDevice m : mMeterList) { if (m.mConnectionState == BluetoothProfile.STATE_DISCONNECTED) { remove.add(m); } } for (MooshimeterDevice m : remove) { mDeviceScrollView.removeView(mTileList.remove(mMeterList.indexOf(m))); mMeterList.remove(m); mMeterDict.remove(m.getAddress()); } refreshAllMeterTiles(); final BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (!bluetoothAdapter.startLeScan(mLeScanCallback)) { // Starting the scan failed! Log.e(TAG, "Failed to start BLE Scan"); setError("Failed to start scan"); } h.postDelayed(new Runnable() { @Override public void run() { mBtnScan.setEnabled(true); updateScanningButton(false); final BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); bluetoothAdapter.stopLeScan(mLeScanCallback); mScanOngoing = false; } }, 5000); }
From source file:com.evothings.BLE.java
private void startScan(final CordovaArgs args, final CallbackContext callbackContext) { final BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); final LeScanCallback self = this; checkPowerState(adapter, callbackContext, new Runnable() { @Override/*from w ww .j av a 2s . c om*/ public void run() { if (!adapter.startLeScan(self)) { callbackContext.error("Android function startLeScan failed"); return; } mScanCallbackContext = callbackContext; } }); }