Java Code Examples for android.bluetooth.le.BluetoothLeScanner#stopScan()
The following examples show how to use
android.bluetooth.le.BluetoothLeScanner#stopScan() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BluetoothAdapter.java From android_9.0.0_r45 with Apache License 2.0 | 8 votes |
/** * Stops an ongoing Bluetooth LE device scan. * * @param callback used to identify which scan to stop must be the same handle used to start the * scan * @deprecated Use {@link BluetoothLeScanner#stopScan(ScanCallback)} instead. */ @Deprecated @RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN) public void stopLeScan(LeScanCallback callback) { if (DBG) { Log.d(TAG, "stopLeScan()"); } BluetoothLeScanner scanner = getBluetoothLeScanner(); if (scanner == null) { return; } synchronized (mLeScanClients) { ScanCallback scanCallback = mLeScanClients.remove(callback); if (scanCallback == null) { if (DBG) { Log.d(TAG, "scan not started yet"); } return; } scanner.stopScan(scanCallback); } }
Example 2
Source File: LollipopScanner.java From RxCentralBle with Apache License 2.0 | 6 votes |
private void stopScan() { BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); if (adapter != null && adapter.isEnabled()) { BluetoothLeScanner bleScanner = adapter.getBluetoothLeScanner(); if (bleScanner != null) { bleScanner.stopScan(scanCallback); } else if (RxCentralLogger.isError()) { RxCentralLogger.error("stopScan - BluetoothLeScanner is null!"); } } else if (RxCentralLogger.isError()) { if (adapter == null) { RxCentralLogger.error("stopScan - Default Bluetooth Adapter is null!"); } else { RxCentralLogger.error("stopScan - Bluetooth Adapter is disabled."); } } scanDataSubject = null; }
Example 3
Source File: ThrottledLollipopScanner.java From RxCentralBle with Apache License 2.0 | 6 votes |
private void stopScan() { BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); if (adapter != null && adapter.isEnabled()) { BluetoothLeScanner bleScanner = adapter.getBluetoothLeScanner(); if (bleScanner != null) { bleScanner.stopScan(scanCallback); } else if (RxCentralLogger.isError()) { RxCentralLogger.error("stopScan - BluetoothLeScanner is null!"); } } else if (RxCentralLogger.isError()) { if (adapter == null) { RxCentralLogger.error("stopScan - Default Bluetooth Adapter is null!"); } else { RxCentralLogger.error("stopScan - Bluetooth Adapter is disabled."); } } }
Example 4
Source File: RxBleAdapterWrapper.java From RxAndroidBle with Apache License 2.0 | 6 votes |
@TargetApi(21 /* Build.VERSION_CODES.LOLLIPOP */) public void stopLeScan(ScanCallback scanCallback) { if (!bluetoothAdapter.isEnabled()) { // this situation seems to be a problem since API 29 RxBleLog.v( "BluetoothAdapter is disabled, calling BluetoothLeScanner.stopScan(ScanCallback) may cause IllegalStateException" ); // if stopping the scan is not possible due to BluetoothAdapter turned off then it is probably stopped anyway return; } final BluetoothLeScanner bluetoothLeScanner = bluetoothAdapter.getBluetoothLeScanner(); if (bluetoothLeScanner == null) { RxBleLog.w( "Cannot call BluetoothLeScanner.stopScan(ScanCallback) on 'null' reference; BluetoothAdapter.isEnabled() == %b", bluetoothAdapter.isEnabled() ); // if stopping the scan is not possible due to BluetoothLeScanner not accessible then it is probably stopped anyway // this should not happen since the check for BluetoothAdapter.isEnabled() has been added above. This situation was only // observed when the adapter was disabled return; } bluetoothLeScanner.stopScan(scanCallback); }
Example 5
Source File: BluetoothLeScannerImplOreo.java From Android-Scanner-Compat-Library with BSD 3-Clause "New" or "Revised" License | 6 votes |
@RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN) /* package */ void stopScanInternal(@NonNull final Context context, @NonNull final PendingIntent callbackIntent) { final BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); final BluetoothLeScanner scanner = adapter.getBluetoothLeScanner(); if (scanner == null) throw new IllegalStateException("BT le scanner not available"); final PendingIntent pendingIntent = createStoppingPendingIntent(context, callbackIntent); scanner.stopScan(pendingIntent); synchronized (wrappers) { // Do not remove the key, just set the value to null. // Based on that we will know that scanning has been stopped. // This is used to discard scanning results delivered after the scan was stopped. // Unfortunately, the callbackIntent will have to be kept and won't he removed, // despite the fact that reports will eventually stop being broadcast. wrappers.put(callbackIntent, null); } }
Example 6
Source File: BluetoothLeScannerImplLollipop.java From Android-Scanner-Compat-Library with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override @RequiresPermission(allOf = {Manifest.permission.BLUETOOTH_ADMIN, Manifest.permission.BLUETOOTH}) /* package */ void stopScanInternal(@NonNull final ScanCallback callback) { ScanCallbackWrapperLollipop wrapper; synchronized (wrappers) { wrapper = wrappers.remove(callback); } if (wrapper == null) return; wrapper.close(); final BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); if (adapter != null) { final BluetoothLeScanner scanner = adapter.getBluetoothLeScanner(); if (scanner != null) scanner.stopScan(wrapper.nativeCallback); } }
Example 7
Source File: SerialInterface_BLE.java From PodEmu with GNU General Public License v3.0 | 6 votes |
@Override public void onScanResult(int callbackType, ScanResult result) { //String bleDeviceAddress = getSharedPref().getString("bluetoothDeviceAddress", "unknown"); //String devName = device.getName() + " [" + device.getAddress() + "]"; //PodEmuLog.debug("SIBLE: device found - " + devName); BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); BluetoothLeScanner bluetoothLeScanner = adapter.getBluetoothLeScanner(); //Do the work below on a worker thread instead! bleDevice = result.getDevice(); bluetoothLeScanner.stopScan(this); setState(STATE_CONNECTING); bleGATT = bleDevice.connectGatt(baseContext, false, bleGattCallback); bleGATT.requestConnectionPriority(BluetoothGatt.CONNECTION_PRIORITY_HIGH); }
Example 8
Source File: L_Util.java From AsteroidOSSync with GNU General Public License v3.0 | 5 votes |
public static void stopNativeScan(BluetoothAdapter adapter) { if (adapter == null) { Log.e("ScanManager", "Tried to stop the scan, but the Bluetooth Adapter instance was null!"); return; } final BluetoothLeScanner scanner = adapter.getBluetoothLeScanner(); if (scanner != null) scanner.stopScan(m_callback); else Log.w("ScanManager", "Tried to stop the scan, but the BluetoothLeScanner instance was null. This implies the scanning has stopped already."); }
Example 9
Source File: SerialInterface_BLE.java From PodEmu with GNU General Public License v3.0 | 5 votes |
@TargetApi(21) public void close() { BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); BluetoothLeScanner bluetoothLeScanner = adapter.getBluetoothLeScanner(); bluetoothLeScanner.stopScan(new MyScanCallback()); if(bleGATT!=null) bleGATT.close(); bleGATT=null; bleDevice=null; bleScanThread=null; mInBuffer.removeAll(); releaseWriteLock(); }
Example 10
Source File: L_Util.java From SweetBlue with GNU General Public License v3.0 | 5 votes |
public static void stopNativeScan(BluetoothAdapter adapter) { if (adapter == null) { Log.e("ScanManager", "Tried to stop the scan, but the Bluetooth Adapter instance was null!"); return; } final BluetoothLeScanner scanner = adapter.getBluetoothLeScanner(); if (scanner != null) scanner.stopScan(m_callback); else Log.w("ScanManager", "Tried to stop the scan, but the BluetoothLeScanner instance was null. This implies the scanning has stopped already."); }