Android 新的棒棒糖API不能检测所有的广告包
我看到过一些帖子有同样的问题,但我没有找到解决问题的方法 我看到新BLEAPI的回调函数(onScanResult)第一次检测到来自外围设备的广告包。我根本看不到后续的数据包。奇怪的是,这种情况只发生在少数设备上。这不会发生在S4上运行棒棒糖,但我已经看到了一加一这个问题。但是我已经能够通过蓝牙Gatt方法连接到外围设备 我还以大约2秒的延迟启动和停止扫描。如果我在棒棒糖设备上使用旧的API,它似乎工作得很好,但是扫描速度似乎慢了很多Android 新的棒棒糖API不能检测所有的广告包,android,bluetooth,android-5.0-lollipop,android-bluetooth,android-ble,Android,Bluetooth,Android 5.0 Lollipop,Android Bluetooth,Android Ble,我看到过一些帖子有同样的问题,但我没有找到解决问题的方法 我看到新BLEAPI的回调函数(onScanResult)第一次检测到来自外围设备的广告包。我根本看不到后续的数据包。奇怪的是,这种情况只发生在少数设备上。这不会发生在S4上运行棒棒糖,但我已经看到了一加一这个问题。但是我已经能够通过蓝牙Gatt方法连接到外围设备 我还以大约2秒的延迟启动和停止扫描。如果我在棒棒糖设备上使用旧的API,它似乎工作得很好,但是扫描速度似乎慢了很多 if (isScanning)
if (isScanning)
{
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
{
if(first_time)
{
first_time = false;
scanner = BluetoothAdapter.getDefaultAdapter().getBluetoothLeScanner();
settings = new ScanSettings.Builder()
.setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY
)
.build();
filters = new ArrayList<ScanFilter>();
}
scanner.startScan(filters, settings, new scancallback());
}else {
mBluetoothAdapter.startLeScan(mLeScanCallback);
}
isScanning = !isScanning;
}
try {
Thread.sleep(2000);
} catch (InterruptedException ie) {
Log.e(TAG, "MonitorThread.InterruptedException-1");
}
if (!isScanning) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
scanner.stopScan(new scancallback());
} else {
mBluetoothAdapter.stopLeScan(mLeScanCallback);
}
isScanning = !isScanning;
}
if(正在扫描)
{
if(Build.VERSION.SDK\u INT>=Build.VERSION\u code.LOLLIPOP)
{
如果(第一次)
{
第一次=错误;
scanner=BluetoothAdapter.getDefaultAdapter().getBluetoothLeScanner();
设置=新的ScanSettings.Builder()
.setScanMode(扫描设置.SCAN_模式\u低延迟
)
.build();
过滤器=新的ArrayList();
}
scanner.startScan(过滤器、设置、新scancallback());
}否则{
mBluetoothAdapter.startedscan(mLeScanCallback);
}
isScanning=!isScanning;
}
试一试{
《睡眠》(2000年);
}捕获(中断异常ie){
Log.e(标记“MonitorThread.InterruptedException-1”);
}
如果(!IsScan){
if(Build.VERSION.SDK\u INT>=Build.VERSION\u code.LOLLIPOP){
scanner.stopScan(新的scancallback());
}否则{
mBluetoothAdapter.stopLeScan(mLeScanCallback);
}
isScanning=!isScanning;
}
有人能解决这个问题吗?我一直在为这个问题绞尽脑汁,但找不到任何线索。任何帮助都将不胜感激。您尝试过其他android版本吗?您尝试过其他android版本吗??