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设备?