小编use*_*879的帖子

BluetoothAdapter不会停止扫描BLE设备

在我的应用程序中我有启动和停止按钮,当用户按下启动时我调用startScan方法

bluetoothAdapter.getBluetoothLeScanner().startScan(getLeScanCallback());
Run Code Online (Sandbox Code Playgroud)

当用户按下停止时,我会调用stopScan,但它似乎什么也没做.BluetoothAdapter会持续扫描新设备.

bluetoothAdapter.getBluetoothLeScanner().stopScan(getLeScanCallback());
Run Code Online (Sandbox Code Playgroud)

这是我的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<ScanResult> results) {
            super.onBatchScanResults(results);
        }

        @Override
        public void onScanFailed(int errorCode) {
            super.onScanFailed(errorCode);
        }
    };

    return leScanCallback;
}
Run Code Online (Sandbox Code Playgroud)

即使在调用stopScan()之后它也会被调用.我做错了什么,换句话说,如何停止扫描BLE设备?

android bluetooth-lowenergy android-bluetooth

9
推荐指数
2
解决办法
7348
查看次数

如何阻止selenium webdriver等待页面加载?

有时,当我进行测试时,网站永远不会停止加载,我的测试就会卡在上面.如何设置driver.get()方法不等待页面加载?如果它不可能有任何工作或其他方法可以取代driver.get()?

java selenium webdriver pageload

4
推荐指数
1
解决办法
8506
查看次数

onLeScan在发现蓝牙设备时调用了两次

我试图发现蓝牙低能耗设备,但我有onLeScan方法的问题.它被调用两次,因此所有设备都加倍了.

我用来启动扫描的方法:

private void scanLeDevice(final boolean enable) {
        if (enable) {
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    bluetoothAdapter.stopLeScan(getLeScanCallback());
                    scanning = false;
                }
            }, SCAN_PERIOD);

            scanning = true;
            bluetoothAdapter.startLeScan(getLeScanCallback());
        } else {
            bluetoothAdapter.stopLeScan(getLeScanCallback());
            scanning = false;
        }
    }
Run Code Online (Sandbox Code Playgroud)

返回LeScanCallback的方法:

private BluetoothAdapter.LeScanCallback getLeScanCallback(){
        BluetoothAdapter.LeScanCallback leScanCallback =
                new BluetoothAdapter.LeScanCallback() {
                    @Override
                    public void onLeScan(final BluetoothDevice bluetoothDevice, int rssi
                            , byte[] scanRecord) {
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                Log.d(TAG, "device found");
                                Device device = new Device();
                                device.setName(bluetoothDevice.getName());
                                device.setAddress(bluetoothDevice.getAddress());
                                devices.add(device); …
Run Code Online (Sandbox Code Playgroud)

android bluetooth bluetooth-lowenergy

1
推荐指数
1
解决办法
873
查看次数