xiaoyaoyou1212 / BLE

✨Android BLE基础操作框架,基于回调,操作简单。包含扫描、多连接、广播包解析、服务读写及通知等功能。
http://www.huwei.tech/
Apache License 2.0
1.38k stars 364 forks source link

设备全扫描的方法,无法停止扫描 #52

Closed kkpyqt closed 6 years ago

kkpyqt commented 6 years ago

我是参考教程写的: 初始化后开如扫描: ViseBle.getInstance().startScan(periodScanCallbackbyall);

private ScanCallback periodScanCallbackbyall = new ScanCallback(new IScanCallback() { @Override public void onDeviceFound(final BluetoothLeDevice bluetoothLeDevice) { ViseLog.i("Founded Scan Device:" + bluetoothLeDevice); onFilter(bluetoothLeDevice); //检查是否有合法设备

    }

    @Override
    public void onScanFinish(BluetoothLeDeviceStore bluetoothLeDeviceStore) {
        ViseLog.i("scan finish " + bluetoothLeDeviceStore);
    }

    @Override
    public void onScanTimeout() {
        ViseLog.i("scan timeout");
    }

});

在这个方法下停上不了扫描 private void onFilter(BluetoothLeDevice bluetoothLeDevice) { String[] blename; blename = new String[]{"Glucose"}; for(int i=0;i<blename.length;i++) { if (bluetoothLeDevice.getDevice().getName().trim().equals(blename[i])) { mac = bluetoothLeDevice.getDevice().getAddress(); connectbymac();

                ViseLog.i("Founded Scan Device:" + mac);
                if (periodScanCallbackbyall != null && periodScanCallbackbyall.isScanning()) {
                    ViseBle.getInstance().stopScan(periodScanCallbackbyall);//找到就停止扫描

                }

//

        }
    }

}
xiaoyaoyou1212 commented 6 years ago

@kkpyqt 看下超时时间设置是不是为-1,demo默认是一直扫描的

kkpyqt commented 6 years ago

非常感谢,我把-1 改为30000 即可,问题已经解决