use of android.bluetooth.le.ScanSettings in project android_frameworks_base by AOSPA.
the class KeyboardUI method startScanning.
private void startScanning() {
BluetoothLeScanner scanner = mLocalBluetoothAdapter.getBluetoothLeScanner();
ScanFilter filter = (new ScanFilter.Builder()).setDeviceName(mKeyboardName).build();
ScanSettings settings = (new ScanSettings.Builder()).setCallbackType(ScanSettings.CALLBACK_TYPE_ALL_MATCHES).setNumOfMatches(ScanSettings.MATCH_NUM_ONE_ADVERTISEMENT).setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY).setReportDelay(0).build();
mScanCallback = new KeyboardScanCallback();
scanner.startScan(Arrays.asList(filter), settings, mScanCallback);
Message abortMsg = mHandler.obtainMessage(MSG_BLE_ABORT_SCAN, ++mScanAttempt, 0);
mHandler.sendMessageDelayed(abortMsg, BLUETOOTH_SCAN_TIMEOUT_MILLIS);
}
use of android.bluetooth.le.ScanSettings in project xDrip-plus by jamorham.
the class BluetoothScan method scanLeDeviceLollipop.
@TargetApi(21)
private synchronized void scanLeDeviceLollipop(final boolean enable) {
if (enable) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
lollipopScanner = bluetooth_adapter.getBluetoothLeScanner();
}
if (lollipopScanner != null) {
Log.d(TAG, "Starting scanner 21");
// Stops scanning after a pre-defined scan period.
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
is_scanning = false;
if (bluetooth_adapter != null && bluetooth_adapter.isEnabled()) {
lollipopScanner.stopScan(mScanCallback);
}
invalidateOptionsMenu();
}
}, SCAN_PERIOD);
ScanSettings settings = new ScanSettings.Builder().setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY).build();
is_scanning = true;
if (bluetooth_adapter != null && bluetooth_adapter.isEnabled()) {
lollipopScanner.startScan(null, settings, mScanCallback);
}
} else {
try {
scanLeDevice(true);
} catch (Exception e) {
Log.e(TAG, "Failed to scan for ble device", e);
}
}
} else {
is_scanning = false;
if (bluetooth_adapter != null && bluetooth_adapter.isEnabled()) {
lollipopScanner.stopScan(mScanCallback);
}
}
invalidateOptionsMenu();
}
use of android.bluetooth.le.ScanSettings in project android_packages_apps_Settings by DirtyUnicorns.
the class AnomalyActions method doUnoptimizedBleScan.
private static void doUnoptimizedBleScan(Context ctx, long durationMs) {
ScanSettings scanSettings = new ScanSettings.Builder().setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY).build();
// perform ble scanning
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (bluetoothAdapter == null || !bluetoothAdapter.isEnabled()) {
Log.e(TAG, "Device does not support Bluetooth or Bluetooth not enabled");
return;
}
BluetoothLeScanner bleScanner = bluetoothAdapter.getBluetoothLeScanner();
if (bleScanner == null) {
Log.e(TAG, "Cannot access BLE scanner");
return;
}
ScanCallback scanCallback = new ScanCallback() {
@Override
public void onScanResult(int callbackType, ScanResult result) {
Log.v(TAG, "called onScanResult");
}
@Override
public void onScanFailed(int errorCode) {
Log.v(TAG, "called onScanFailed");
}
@Override
public void onBatchScanResults(List<ScanResult> results) {
Log.v(TAG, "called onBatchScanResults");
}
};
bleScanner.startScan(null, scanSettings, scanCallback);
try {
Thread.sleep(durationMs);
} catch (InterruptedException e) {
Log.e(TAG, "Thread couldn't sleep for " + durationMs, e);
}
bleScanner.stopScan(scanCallback);
}
use of android.bluetooth.le.ScanSettings in project platform_packages_apps_Settings by BlissRoms.
the class AnomalyActions method doUnoptimizedBleScan.
private static void doUnoptimizedBleScan(Context ctx, long durationMs) {
ScanSettings scanSettings = new ScanSettings.Builder().setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY).build();
// perform ble scanning
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (bluetoothAdapter == null || !bluetoothAdapter.isEnabled()) {
Log.e(TAG, "Device does not support Bluetooth or Bluetooth not enabled");
return;
}
BluetoothLeScanner bleScanner = bluetoothAdapter.getBluetoothLeScanner();
if (bleScanner == null) {
Log.e(TAG, "Cannot access BLE scanner");
return;
}
ScanCallback scanCallback = new ScanCallback() {
@Override
public void onScanResult(int callbackType, ScanResult result) {
Log.v(TAG, "called onScanResult");
}
@Override
public void onScanFailed(int errorCode) {
Log.v(TAG, "called onScanFailed");
}
@Override
public void onBatchScanResults(List<ScanResult> results) {
Log.v(TAG, "called onBatchScanResults");
}
};
bleScanner.startScan(null, scanSettings, scanCallback);
try {
Thread.sleep(durationMs);
} catch (InterruptedException e) {
Log.e(TAG, "Thread couldn't sleep for " + durationMs, e);
}
bleScanner.stopScan(scanCallback);
}
use of android.bluetooth.le.ScanSettings in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class AnomalyActions method doUnoptimizedBleScan.
private static void doUnoptimizedBleScan(Context ctx, long durationMs) {
ScanSettings scanSettings = new ScanSettings.Builder().setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY).build();
// perform ble scanning
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (bluetoothAdapter == null || !bluetoothAdapter.isEnabled()) {
Log.e(TAG, "Device does not support Bluetooth or Bluetooth not enabled");
return;
}
BluetoothLeScanner bleScanner = bluetoothAdapter.getBluetoothLeScanner();
if (bleScanner == null) {
Log.e(TAG, "Cannot access BLE scanner");
return;
}
ScanCallback scanCallback = new ScanCallback() {
@Override
public void onScanResult(int callbackType, ScanResult result) {
Log.v(TAG, "called onScanResult");
}
@Override
public void onScanFailed(int errorCode) {
Log.v(TAG, "called onScanFailed");
}
@Override
public void onBatchScanResults(List<ScanResult> results) {
Log.v(TAG, "called onBatchScanResults");
}
};
bleScanner.startScan(null, scanSettings, scanCallback);
try {
Thread.sleep(durationMs);
} catch (InterruptedException e) {
Log.e(TAG, "Thread couldn't sleep for " + durationMs, e);
}
bleScanner.stopScan(scanCallback);
}
Aggregations