Now I am using the new BLE api for Android development.
The basic idea is to use the result of a Bluetooth scan to inflate a recyclerview (list);
I followed the BLE guide on google developer
Now I have two problems: 1. The onBatchScanResults
listener never starts, but onScanResult
works well, is it because the scanner only senses 1 sensor nearby?
- my BLE scanner is much slower compared to other applications.
The following is a code snippet of two main functions.
private void scanBLE(boolean enable) { final BluetoothLeScanner mBluetoothLeScanner = mBluetoothAdapter.getBluetoothLeScanner(); if (enable) { mScanning = true; mBluetoothLeScanner.startScan(mScanCallback); } else { if (mScanning) { mScanning = false; mBluetoothLeScanner.stopScan(mScanCallback); } } Log.i(TAG, "now the scanning state is" + mScanning); }
in MainFragment is as follows:
beaconsList = new ArrayList<BeaconsInfo>(); mAdapter = new BeaconsAdapter(beaconsList); mRecyclerView.setAdapter(mAdapter); scannBLE(true);
Haven source share