android 蓝牙不停扫描,android – BluetoothAdapter不会停止扫描BLE设备
在我的應(yīng)用程序中我有啟動(dòng)和停止按鈕,當(dāng)用戶按下啟動(dòng)時(shí)我調(diào)用startScan方法
bluetoothAdapter.getBluetoothLeScanner().startScan(getLeScanCallback());
當(dāng)用戶按下停止時(shí),我會(huì)調(diào)用stopScan,但它似乎什么也沒(méi)做. BluetoothAdapter會(huì)持續(xù)掃描新設(shè)備.
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;
}
即使在調(diào)用stopScan()之后它也會(huì)被調(diào)用.我做錯(cuò)了什么,換句話說(shuō),如何停止掃描BLE設(shè)備?
總結(jié)
以上是生活随笔為你收集整理的android 蓝牙不停扫描,android – BluetoothAdapter不会停止扫描BLE设备的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: APM和PIX飞控日志分析入门贴
- 下一篇: C++的6种位运算符