AltBeacon正在停止信标扫描.但是继续扫描



它被设计为每4秒扫描一次。然而,从扫描的开始到停止,可能无法检测到信标
之后,停止扫描后会检测到信标。

该问题发生在日志中的以下日期和时间
08:54:28.007 D/CycledLeScanner(21211):扫描开始
08-54:21.906 D/Cycled LeScanner

在这个问题发生后,扫描总是完成的
此问题会关闭设备上的蓝牙。或者,如果您退出应用程序,问题就会得到解决。当我让程序运行了12个小时时,出现了这个问题
这种情况似乎很少发生,但我不知道是什么触发了它。
有人能帮我解决这个问题吗
下面列出了终端信息、源代码和日志。

arrows M03
Android OS 6.0
'org.altbeacon:Android信标库:2.16.2'

主要活动

public class MainActivity extends AppCompatActivity implements BeaconConsumer {
private BeaconManager beaconManager;
Region mRegion;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
beaconManager = BeaconManager.getInstanceForApplication(this);
beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24"));
beaconManager.getBeaconParsers().remove(0);
beaconManager.setForegroundBetweenScanPeriod(4000);
mRegion = new Region("ibeacon", null, null, null);
Button btnFore = (Button) findViewById(R.id.btnFore);
btnFore.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
beaconManager.bind(MainActivity.this);
beaconManager.setDebug(true);
}
});
thdWriteLog l_thdWriteLog = new thdWriteLog();
l_thdWriteLog.start();
}
@Override
public void onBeaconServiceConnect() {
beaconManager.addMonitorNotifier(new MonitorNotifier() {
@Override
public void didEnterRegion(Region region) {}
@Override
public void didExitRegion(Region region) {}
@Override
public void didDetermineStateForRegion(int i, Region region) {}
});
try {
beaconManager.startMonitoringBeaconsInRegion(mRegion);
} catch (RemoteException e) {
e.printStackTrace();
}
beaconManager.addRangeNotifier(new RangeNotifier() {
@Override
public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) {}
});
}

输出日志程序

public class thdWriteLog extends Thread {
@Override
public void run() {
java.lang.Process proc = null;
BufferedReader reader = null;
PrintWriter writer = null;
final String pId =  Integer.toString(android.os.Process.myPid());
try {
proc = Runtime.getRuntime().exec(new String[] { "logcat", "-v", "time"});
reader = new BufferedReader(new InputStreamReader(proc.getInputStream()), 1024);
String line;
while ( true ) {
line = reader.readLine();
if (line.length() == 0) {
try {
Thread.sleep(200);
} catch (InterruptedException e) {
}
continue;
}
if (line.indexOf(pId) != -1) {
try {
OutputStream out;
File l_file = new File(Environment.getExternalStorageDirectory().getPath() + "/log.text");
out = new FileOutputStream(l_file, true);
writer = new PrintWriter(new OutputStreamWriter(out,"UTF-8"));
String l_time = line.substring(0, 18);
String l_logType = line.substring(19, 21);
String l_logStr1 = line.substring(21, line.indexOf("):") + 2);
String l_logStr2 = line.substring(line.indexOf("):") + 3);
String l_logStr = l_time + ',' + l_logType + ',' + l_logStr1 + ',' + l_logStr2;
writer.println(l_logStr);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (writer != null) {
writer.close();
}
}
}
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}

记录

08:54:16.812 D/CycledLeScanner(21211):在4000到3987的扫描周期之间进行标准化
08:54:116.812 D/CycledLeScannerForLollipop(21211
08:54:16.812 D/CycledLeScannerForLollipop/>08:54:18.818 D/CycledLeScannerForLollipop(21211):等待再开始1981毫秒的完全蓝牙扫描
08:54:19.820 D/CycledLeScannerForLollipop(21211/>08:54:2.0805 D/CycledLeScannerForLollipop已启动
08:54:21.810 D/CycledLeScanner(21211):等待再停止扫描周期95毫秒
08:54:21.906 D/CycledLeScannerD/CycledLeScanner(21211):扫描周期从4000到3560之间的标准化
08:54:22.339 D/CycledLeScannerForLollipop(21211
08:54:22.242 D/CycledLeScannerForLollipop(21211):等待再启动3560毫秒的完整蓝牙扫描
08:53:22.813 D/CycleDLeScannerforLollippo(212十一):在扫描处理程序上停止LE扫描
08:54:22.814 D/蓝牙适配器(212十一扫描失败:无法注册应用程序
08:54:23.430 D/CycledLeScannerForLollipopD/BeaconsParser(21211):正在处理pdu类型FF:0211a0bff4c0009060301c0a8000f0000000000000000000000000000000000000000000000000000000000000000000,startIndex:5endIndex:14
08:54:23.643 D/Beaconsarser(212十一):这不是匹配的Beacon播发。(原本预计02 15。我看到的字节是:02011a0bff4c0009060301c0a8000f0000000000000000000000000000000000000000000000000000000000000000000
08:54:23.669 D/CycleDeScannerForLollipop1eff060001092002d9da8d7c318ba216cf4f0f1840361ab991a8f9fe57a93c00000000000000000000000000000000000000带startIndex:2 endIndex:30
08:54:23.670 D/Beacon Parser(21211):这不是匹配的Beacon广告。(原本预计02 15。我看到的字节是:1eff060001092002d9da8d7c318ba216cf4fff1840361ab991a8f9fe57a93c00000000000000000000000000000000000000
08:54:23.677 D/CycledLeScannerForLollipop(21211):得到记录
08.54:23.678 D/BeaconsParser(212110201061aff4c000215b9407f90f5f8466eaff925556b57fe6d00000000c400000000000000000000000000000000000000000000000000000000000000带起始索引:5结束索引:29
08:54:23.679 D/信标解析程序(21211):这是一个已识别的信标广告--02 15可见
08-54:23.699 D/信标解析器(212110201061aff4c000215b9407f90f5f8466eaff925556b57fe6d00000000c400000000000000000000000000000000000000000000000000000000000000
08:54:23.691 D/ScanHelper(21211:b9407f90-f5f8-466e-aff9-25556b57fe6d id2:0 id3:0
08:54:23.696 D/Beacon Parser(21211):忽略pdu类型01
08:54:23.999 D/Beacon解析器(21211

在日志中显示的情况下,停止扫描的底层Android API命令失败:

08:54:22.813 D/CycledLeScannerForLollipop(21211): Stopping LE scan on scan handler
08:54:22.814 D/BluetoothAdapter(21211): STATE_ON
08:54:22.814 D/BluetoothLeScanner(21211): could not find callback wrapper
08:54:23.430 E/ CycledLeScannerForLollipop(21211): Scan failed: app cannot be registered

上面最后一行写着";扫描失败";,这实际上是指试图停止扫描。

这肯定是测试设备上蓝牙堆栈内部的问题。由于Android蓝牙堆栈和底层蓝牙芯片之间的接口总是涉及OEM的一些专有定制,这很可能是由于该实现中的一些错误造成的。

由于你无法修复蓝牙堆栈,你最好的办法是尝试找到某种变通方法来重新控制扫描。这无疑需要反复试验。您可以尝试禁用Android Beacon Library的扫描服务,然后重新启动它,方法是停止所有监控(如果正在进行测距),等待30秒,然后重新开始监控(如果需要,还可以进行测距)。

最新更新