Java Code Examples for android.bluetooth.BluetoothAdapter#startDiscovery()
The following examples show how to use
android.bluetooth.BluetoothAdapter#startDiscovery() .
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: BluetoothDeviceListProvider.java From PrivacyStreams with Apache License 2.0 | 5 votes |
@Override protected void provide() { BluetoothAdapter BTAdapter = BluetoothAdapter.getDefaultAdapter(); // Set up the adaptor if (BTAdapter == null || !BTAdapter.isEnabled()) { this.finish(); return; } IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(android.bluetooth.BluetoothDevice.ACTION_FOUND); intentFilter.addAction(BluetoothAdapter.ACTION_DISCOVERY_STARTED); intentFilter.addAction(BluetoothAdapter.ACTION_DISCOVERY_FINISHED); getContext().registerReceiver(mReceiver, intentFilter); BTAdapter.startDiscovery(); }
Example 2
Source File: P_BluetoothCrashResolver.java From AsteroidOSSync with GNU General Public License v3.0 | 5 votes |
@TargetApi(17) private void startRecovery() { // The discovery operation will start by clearing out the bluetooth mac list to only the 256 // most recently seen BLE mac addresses. recoveryAttemptCount++; BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); if (isDebugEnabled()) Log.d(TAG, "about to check if discovery is active"); if (!adapter.isDiscovering()) { Log.w(TAG, "Recovery attempt started"); recoveryInProgress = true; discoveryStartConfirmed = false; if (isDebugEnabled()) Log.d(TAG, "about to command discovery"); if (!adapter.startDiscovery()) { Log.w(TAG, "Can't start discovery. Is bluetooth turned on?"); } if (isDebugEnabled()) Log.d(TAG, "startDiscovery commanded. isDiscovering()="+adapter.isDiscovering()); // We don't actually need to do a discovery -- we just need to kick one off so the // mac list will be pared back to 256. Because discovery is an expensive operation in // terms of battery, we will cancel it. if (TIME_TO_LET_DISCOVERY_RUN_MILLIS > 0 ) { if (isDebugEnabled()) Log.d(TAG, "We will be cancelling this discovery in "+TIME_TO_LET_DISCOVERY_RUN_MILLIS+" milliseconds."); discoveryCanceller.doInBackground(); } else { Log.d(TAG, "We will let this discovery run its course."); } } else { Log.w(TAG, "Already discovering. Recovery attempt abandoned."); } }
Example 3
Source File: InsightPairingActivity.java From AndroidAPS with GNU Affero General Public License v3.0 | 5 votes |
private void startBLScan() { if (!scanning) { BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (bluetoothAdapter != null) { if (!bluetoothAdapter.isEnabled()) bluetoothAdapter.enable(); IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(BluetoothAdapter.ACTION_DISCOVERY_FINISHED); intentFilter.addAction(BluetoothDevice.ACTION_FOUND); registerReceiver(broadcastReceiver, intentFilter); bluetoothAdapter.startDiscovery(); scanning = true; } } }
Example 4
Source File: P_BluetoothCrashResolver.java From SweetBlue with GNU General Public License v3.0 | 5 votes |
@TargetApi(17) private void startRecovery() { // The discovery operation will start by clearing out the bluetooth mac list to only the 256 // most recently seen BLE mac addresses. recoveryAttemptCount++; BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); if (isDebugEnabled()) Log.d(TAG, "about to check if discovery is active"); if (!adapter.isDiscovering()) { Log.w(TAG, "Recovery attempt started"); recoveryInProgress = true; discoveryStartConfirmed = false; if (isDebugEnabled()) Log.d(TAG, "about to command discovery"); if (!adapter.startDiscovery()) { Log.w(TAG, "Can't start discovery. Is bluetooth turned on?"); } if (isDebugEnabled()) Log.d(TAG, "startDiscovery commanded. isDiscovering()="+adapter.isDiscovering()); // We don't actually need to do a discovery -- we just need to kick one off so the // mac list will be pared back to 256. Because discovery is an expensive operation in // terms of battery, we will cancel it. if (TIME_TO_LET_DISCOVERY_RUN_MILLIS > 0 ) { if (isDebugEnabled()) Log.d(TAG, "We will be cancelling this discovery in "+TIME_TO_LET_DISCOVERY_RUN_MILLIS+" milliseconds."); discoveryCanceller.doInBackground(); } else { Log.d(TAG, "We will let this discovery run its course."); } } else { Log.w(TAG, "Already discovering. Recovery attempt abandoned."); } }
Example 5
Source File: BluetoothCrashResolver.java From android-beacon-library with Apache License 2.0 | 5 votes |
@TargetApi(17) private void startRecovery() { // The discovery operation will start by clearing out the Bluetooth mac list to only the 256 // most recently seen BLE mac addresses. recoveryAttemptCount++; BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); LogManager.d(TAG, "about to check if discovery is active"); if (!adapter.isDiscovering()) { LogManager.w(TAG, "Recovery attempt started"); recoveryInProgress = true; discoveryStartConfirmed = false; LogManager.d(TAG, "about to command discovery"); if (!adapter.startDiscovery()) { LogManager.w(TAG, "Can't start discovery. Is Bluetooth turned on?"); } LogManager.d(TAG, "startDiscovery commanded. isDiscovering()=%s", adapter.isDiscovering()); // We don't actually need to do a discovery -- we just need to kick one off so the // mac list will be pared back to 256. Because discovery is an expensive operation in // terms of battery, we will cancel it. if (TIME_TO_LET_DISCOVERY_RUN_MILLIS > 0 ) { LogManager.d(TAG, "We will be cancelling this discovery in %s milliseconds.", TIME_TO_LET_DISCOVERY_RUN_MILLIS); cancelDiscovery(); } else { LogManager.d(TAG, "We will let this discovery run its course."); } } else { LogManager.w(TAG, "Already discovering. Recovery attempt abandoned."); } }
Example 6
Source File: BluetoothCrashResolver.java From android-sdk with MIT License | 5 votes |
@TargetApi(17) private void startRecovery() { // The discovery operation will start by clearing out the bluetooth mac list to only the 256 // most recently seen BLE mac addresses. recoveryAttemptCount++; BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); if (isDebugEnabled()) Log.d(TAG, "about to check if discovery is active"); if (!adapter.isDiscovering()) { Logger.log.verbose("Recovery attempt started"); recoveryInProgress = true; discoveryStartConfirmed = false; if (isDebugEnabled()) Log.d(TAG, "about to command discovery"); if (!adapter.startDiscovery()) { Logger.log.verbose("Can't start discovery. Is bluetooth turned on?"); } if (isDebugEnabled()) Log.d(TAG, "startDiscovery commanded. isDiscovering()="+adapter.isDiscovering()); // We don't actually need to do a discovery -- we just need to kick one off so the // mac list will be pared back to 256. Because discovery is an expensive operation in // terms of battery, we will cancel it. if (TIME_TO_LET_DISCOVERY_RUN_MILLIS > 0 ) { if (isDebugEnabled()) Log.d(TAG, "We will be cancelling this discovery in "+TIME_TO_LET_DISCOVERY_RUN_MILLIS+" milliseconds."); discoveryCanceller.doInBackground(); } else { Logger.log.verbose("We will let this discovery run its course."); } } else { Logger.log.verbose("Already discovering.Recovery attempt abandoned."); } }
Example 7
Source File: BluetoothScanner.java From Rumble with GNU General Public License v3.0 | 4 votes |
private void performScan(boolean force) { try { lock.lock(); switch (scanningState) { case SCANNING_OFF: return; case SCANNING_IN_PROGRESS: return; case SCANNING_SCHEDULED: if(!force) return; else { handler.removeCallbacks(scanScheduleFires); scanningState = ScanningState.SCANNING_IDLE; } case SCANNING_IDLE: break; } /* if((mAccelerometer != null) && !sensorregistered) { mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_NORMAL); sensorregistered = true; } */ BluetoothAdapter mBluetoothAdapter = BluetoothUtil.getBluetoothAdapter(RumbleApplication.getContext()); if (mBluetoothAdapter == null) { Log.d(TAG, "Bluetooth is not supported on this platform"); return; } if( mBluetoothAdapter.isEnabled() ){ btNeighborhood.clear(); /* * it is possible that the device is already discovering if another app * ran a discovery procedure */ if (!mBluetoothAdapter.isDiscovering()) mBluetoothAdapter.startDiscovery(); scanningState = ScanningState.SCANNING_IN_PROGRESS; EventBus.getDefault().post(new BluetoothScanStarted()); /* * we set a timeout in case the scanning discovery procedure doesn't stop by itself * (yes. it does happen too.) */ handler.postDelayed(scanTimeoutFires, (long)SCANNING_TIMEOUT); } } catch (Exception e) { Log.d(TAG, "Exception:"+e.toString()); } finally { lock.unlock(); } }