android 蓝牙不停扫描,android – BluetoothAdapter不会停止扫描BLE设备
在我的應用程序中我有啟動和停止按鈕,當用戶按下啟動時我調用startScan方法
bluetoothAdapter.getBluetoothLeScanner().startScan(getLeScanCallback());
當用戶按下停止時,我會調用stopScan,但它似乎什么也沒做. BluetoothAdapter會持續掃描新設備.
bluetoothAdapter.getBluetoothLeScanner().stopScan(getLeScanCallback());
這是我的getLeScanCallback方法:
private ScanCallback getLeScanCallback(){
ScanCallback leScanCallback = new ScanCallback() {
@Override
public void onScanResult(int callbackType, ScanResult result) {
super.onScanResult(callbackType, result);
boolean duplicate = false;
for(Device d : devices) {
if(d.getAddress().equals(result.getDevice().getAddress()))
duplicate = true;
}
if(!duplicate) {
Device device = new Device();
device.setName(result.getDevice().getName());
device.setAddress(result.getDevice().getAddress());
device.setStatus(getString(R.string.disconnected));
devices.add(device);
deviceListAdapter.notifyDataSetChanged();
}
}
@Override
public void onBatchScanResults(List results) {
super.onBatchScanResults(results);
}
@Override
public void onScanFailed(int errorCode) {
super.onScanFailed(errorCode);
}
};
return leScanCallback;
}
即使在調用stopScan()之后它也會被調用.我做錯了什么,換句話說,如何停止掃描BLE設備?
總結
以上是生活随笔為你收集整理的android 蓝牙不停扫描,android – BluetoothAdapter不会停止扫描BLE设备的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: APM和PIX飞控日志分析入门贴
- 下一篇: lodop打印html内容,Lodop打