android_study_2
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revision | |||
| android_study_2 [2020/03/10 03:03] – [Service] jrseti | android_study_2 [2020/03/10 03:06] (current) – [BLE] jrseti | ||
|---|---|---|---|
| Line 54: | Line 54: | ||
| ====BLE==== | ====BLE==== | ||
| + | < | ||
| + | final BluetoothManager bluetoothManager = | ||
| + | (BluetoothManager)getSystemService(Context.BLUETOOTH_SERVICE); | ||
| + | mBluetoothAdapter = bluetoothManager.getAdapter(); | ||
| + | | ||
| + | mLEScanner = mBluetoothAdapter.getBluetoothLeScanner(); | ||
| + | settings = new ScanSettings.Builder() | ||
| + | .setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY) | ||
| + | .build(); | ||
| + | | ||
| + | filters = new ArrayList< | ||
| + | ScanFilter scanFilter = new ScanFilter.Builder() | ||
| + | .setServiceUuid(ParcelUuid.fromString(FILTER_UUID)) | ||
| + | .build(); | ||
| + | filters.add(scanFilter); | ||
| + | | ||
| + | IntentFilter filter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED); | ||
| + | registerReceiver(mBLEStateChangedReceiver, | ||
| + | </ | ||
| + | |||
| + | * Then start scanning and get the scan callbacks: | ||
| + | |||
| + | < | ||
| + | private ScanCallback mScanCallback = new ScanCallback() { | ||
| + | @Override | ||
| + | public void onScanResult(int callbackType, | ||
| + | </ | ||
| ====Service==== | ====Service==== | ||
android_study_2.1583809435.txt.gz · Last modified: 2020/03/10 03:03 by jrseti