【发布时间】:2020-12-14 06:44:47
【问题描述】:
设计为每 4 秒扫描一次。
但是,从扫描开始到停止,可能无法检测到信标。
之后,停止扫描后检测到信标。
问题出现在日志中的以下日期和时间。
08:54:20.807 D/CycledLeScanner(21211):扫描开始
08:54:21.906 D/CycledLeScanner(21211):完成扫描周期
08:54:22.336 D/Cycled LeScanner(21211):停止蓝牙文件扫描
08:54:23.638 D/CycledLeScannerForLollipop(21211): 得到记录
出现此问题后,扫描始终完成。
此问题会关闭设备上的蓝牙。或者,如果您退出应用程序,它将得到解决。当我让程序运行 12 小时时出现此问题。
它似乎很少发生,但我不知道是什么触发了它。
谁能帮我解决这个问题?
下面列出了终端信息、源代码和日志。
箭头 M03
安卓操作系统 6.0
'org.altbeacon:android-beacon-library: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:16.812 D/CycledLeScannerForLollipop(21211):这是 Android L,但我们最后一次看到信标是在 10 年前,所以我们不会在后台继续扫描。
08:54:16.812 D/CycledLeScannerForLollipop(21211):等待开始完整的蓝牙扫描另外 3987 毫秒
08:54:16.812 D/CycledLeScannerForLollipop(21211):在扫描处理程序上停止 LE 扫描
08:54:16.814 D/蓝牙适配器(21211):STATE_ON
08:54:17.815 D/CycledLeScannerForLollipop(21211):等待开始完整的蓝牙扫描另外 2984 毫秒
08:54:18.818 D/CycledLeScannerForLollipop(21211):等待开始完整的蓝牙扫描另外 1981 毫秒
08:54:19.820 D/CycledLeScannerForLollipop(21211):等待开始完整的蓝牙扫描另外 979 毫秒
08:54:20.801 D/CycledLeScanner(21211):开始新的扫描周期
08:54:20.803 D/CycledLeScanner(21211):开始新的蓝牙文件扫描
08:54:20.805 D/CycledLeScannerForLollipop(21211):在 SCAN_MODE_LOW_LATENCY 中开始扫描
08:54:20.805 D/CycledLeScannerForLollipop(21211):不使用扫描过滤器,因为这是 8.1 之前的版本
08:54:20.806 D/蓝牙适配器(21211):STATE_ON
08:54:20.807 D/CycledLeScanner(21211):等待再停止扫描周期 1100 毫秒
08:54:20.807 D/CycledLeScanner(21211):扫描开始
08:54:21.810 D/CycledLeScanner(21211):等待再停止扫描周期 95 毫秒
08:54:21.906 D/CycledLeScanner(21211):完成扫描周期
08:54:21.906 D/ScanHelper(21211):信标模拟器未启用
08:54:22.336 D/CycledLeScanner(21211):停止蓝牙文件扫描
08:54:22.336 D/CycledLeScannerForLollipop(21211):停止扫描
08:54:22.339 D/CycledLeScanner(21211):在 4000 到 3560 的扫描周期之间进行归一化
08:54:22.339 D/CycledLeScannerForLollipop(21211):这是 Android L,但我们最后一次看到信标是在 5537 年前,所以我们不会在后台继续扫描。
08:54:22.342 D/CycledLeScannerForLollipop(21211):等待开始完整的蓝牙扫描另外 3560 毫秒
08:54:22.813 D/CycledLeScannerForLollipop(21211):在扫描处理程序上停止 LE 扫描
08:54:22.814 D/蓝牙适配器(21211):STATE_ON
08:54:22.814 D/BluetoothLeScanner(21211): 找不到回调包装器
08:54:23.430 E/CycledLeScannerForLollipop(21211):扫描失败:无法注册应用程序
08:54:23.430 D/CycledLeScannerForLollipop(21211):等待开始完整的蓝牙扫描另外 2469 毫秒
08:54:23.468 D/BluetoothLeScanner(21211): onClientRegistered() - status=0 clientIf=7
08:54:23.638 D/CycledLeScannerForLollipop(21211):获得记录
08:54:23.643 D/BeaconParser(21211):忽略 pdu 类型 01
08:54:23.643 D/BeaconParser(21211): Processing pdu type FF: 02011a0bff4c0009060301c0a8000f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 with startIndex: 5 endIndex: 14
08:54:23.643 D/BeaconParser(21211):这不是匹配的 Beacon 广告。 (期待02 15。我看到的字节是:02011a0bff4c0009060301c0a8000f00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 08:54:23.669 D/CycledLeScannerForLollipop(21211):获得记录
08:54:23.670 D/BEACONPARSER(21211):处理PDU类型FF:1EFF060001092D9D9DA8D7C318BA216CF4F4F4F4F0F1840361AB991AB991AB91AB91A8F91A8F570000000000000000000000000000000000000000000000来: 08:54:23.670 D/BeaconParser(21211):这不是匹配的 Beacon 广告。 (期待02 15。我看到的字节是:1eff060001092002d9da8d7c318ba216cf4f0f1840361ab991a8f9fe57a93c0000000000000000000000000000000000000000000000000000000000000000 08:54:23.677 D/CycledLeScannerForLollipop(21211):获得记录
08:54:23.678 D/BeaconParser(21211):忽略 pdu 类型 01
08:54:23.678 D/BeaconParser(21211): Processing pdu type FF: 0201061aff4c000215b9407f90f5f8466eaff925556b57fe6d00000000c40000000000000000000000000000000000000000000000000000000000000000 with startIndex: 5 endIndex: 29
08:54:23.679 D/BeaconParser(21211):这是公认的信标广告 -- 02 15 看到
08:54:23.679 D/BeaconParser(21211): Bytes are: 0201061aff4c000215b9407f90f5f8466eaff925556b57fe6d00000000c40000000000000000000000000000000000000000000000000000000000000000
08:54:23.691 D/ScanHelper(21211): 检测到信标包: id1: b9407f90-f5f8-466e-aff9-25556b57fe6d id2: 0 id3: 0 with rssi -62
08:54:23.695 D/CycledLeScannerForLollipop(21211):获得记录
08:54:23.695 D/ScanHelper(21211): 检测到信标: id1: b9407f90-f5f8-466e-aff9-25556b57fe6d id2: 0 id3: 0
08:54:23.696 D/BeaconParser(21211):忽略 pdu 类型 01
08:54:23.699 D/BeaconParser(21211): Processing pdu type FF: 0201061aff4c000215d9407f30f5f8466eaff925556b57fe6d00000000c40000000000000000000000000000000000000000000000000000000000000000 with startIndex: 5 endIndex: 29
08:54:23.703 D/BeaconParser(21211):这是公认的信标广告 -- 02 15 看到
08:54:23.706 D/BeaconParser(21211): Bytes are: 0201061aff4c000215d9407f30f5f8466eaff925556b57fe6d00000000c40000000000000000000000000000000000000000000000000000000000000000
08:54:23.719 D/CycledLeScannerForLollipop(21211):获得记录
08:54:23.720 D/BeaconParser(21211):忽略 pdu 类型 01
08:54:23.720 D/BeaconParser(21211): Processing pdu type FF: 0201061aff4c000215b9407f30f5f8466eaff925556b57fe6d00000000c40000000000000000000000000000000000000000000000000000000000000000 with startIndex: 5 endIndex: 29
08:54:23.720 D/ScanHelper(21211): 检测到信标包: id1: d9407f30-f5f8-466e-aff9-25556b57fe6d id2: 0 id3: 0 with rssi -64
08:54:23.720 D/BeaconParser(21211):这是一个公认的信标广告 -- 02 15 看到
08:54:23.720 D/ScanHelper(21211): 检测到信标: id1: d9407f30-f5f8-466e-aff9-25556b57fe6d id2: 0 id3: 0
08:54:23.720 D/BeaconParser(21211): Bytes are: 0201061aff4c000215b9407f30f5f8466eaff925556b57fe6d00000000c40000000000000000000000000000000000000000000000000000000000000000
08:54:23.720 D/ScanHelper(21211):寻找此信标的测距区域匹配
08:54:23.724 D/ScanHelper(21211): 检测到信标包: id1: b9407f30-f5f8-466e-aff9-25556b57fe6d id2: 0 id3: 0 with rssi -60
08:54:23.724 D/ScanHelper(21211):寻找此信标的测距区域匹配
08:54:23.724 D/ScanHelper(21211): 检测到信标: id1: b9407f30-f5f8-466e-aff9-25556b57fe6d id2: 0 id3: 0
08:54:23.724 D/ScanHelper(21211):寻找此信标的测距区域匹配
08:54:23.778 D/CycledLeScannerForLollipop(21211):获得记录
08:54:23.779 D/BeaconParser(21211):忽略 pdu 类型 01
08:54:23.779 D/BeaconParser(21211): Processing pdu type FF: 0201061aff4c000215b9407f90f5f8466eaff925556b57fe6d00000000c40000000000000000000000000000000000000000000000000000000000000000 with startIndex: 5 endIndex: 29
08:54:23.779 D/BeaconParser(21211):这是一个公认的信标广告 -- 02 15 看到
08:54:23.780 D/BeaconParser(21211): Bytes are: 0201061aff4c000215b9407f90f5f8466eaff925556b57fe6d00000000c40000000000000000000000000000000000000000000000000000000000000000
08:54:23.784 D/ScanHelper(21211): 检测到信标包: id1: b9407f90-f5f8-466e-aff9-25556b57fe6d id2: 0 id3: 0 with rssi -72
08:54:23.784 D/ScanHelper(21211): 检测到信标: id1: b9407f90-f5f8-466e-aff9-25556b57fe6d id2: 0 id3: 0
08:54:23.785 D/ScanHelper(21211):寻找此信标的测距区域匹配
08:54:23.797 D/CycledLeScannerForLollipop(21211):获得记录
08:54:23.798 D/BeaconParser(21211): Processing pdu type FF: 1aff4c000215b9407f91f5f8466eaff925556b57fe6d00000000c40000000000000000000000000000000000000000000000000000000000000000000000 with startIndex: 2 endIndex: 26
08:54:23.798 D/BeaconParser(21211): 这是一个公认的信标广告 -- 02 15 看到
08:54:23.798 D/BEACONPARSER(21211):字节为:1AFF4C000215B9407F91F91F5F55F8466AEFF925555557FE6B57FE6D000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000来了 08:54:23.801 D/ScanHelper(21211): 检测到信标包: id1: b9407f91-f5f8-466e-aff9-25556b57fe6d id2: 0 id3: 0 with rssi -71
08:54:23.801 D/ScanHelper(21211): 检测到信标: id1: b9407f91-f5f8-466e-aff9-25556b57fe6d id2: 0 id3: 0
08:54:23.802 D/ScanHelper(21211):寻找此信标的测距区域匹配
08:54:23.888 D/CycledLeScannerForLollipop(21211):获得记录
08:54:23.892 D/BEACONPARSER(21211):处理PDU类型FF:1EFF06000109292929291ED7A8667FAFFF88483E841CB1B14CA9A67F84CA67F8EB84AAA2000000000000000000000000000000000000000000000000000000000000个: 08:54:23.892 D/BeaconParser(21211):这不是匹配的 Beacon 广告。 (期待02 15。我看到的字节是:1eff0600010920029291ed7a8667fafff88483e841cb14ca9a67f8eb84aaa20000000000000000000000000000000000000000000000000000000000000 08:54:23.965 D/CycledLeScannerForLollipop(21211):获得记录
08:54:23.966 D/BeaconParser(21211):忽略 pdu 类型 01
08:54:23.966 D/BeaconParser(21211): Processing pdu type FF: 0201061aff4c000215b9407f90f5f8466eaff925556b57fe6d00000000c40000000000000000000000000000000000000000000000000000000000000000 with startIndex: 5 endIndex: 29
08:54:23.966 D/BeaconParser(21211):这是公认的信标广告 -- 02 15 看到
08:54:23.966 D/BeaconParser(21211): Bytes are: 0201061aff4c000215b9407f90f5f8466eaff925556b57fe6d00000000c40000000000000000000000000000000000000000000000000000000000000000
08:54:23.977 D/ScanHelper(21211): 检测到信标包: id1: b9407f90-f5f8-466e-aff9-25556b57fe6d id2: 0 id3: 0 with rssi -72
08:54:23.977 D/ScanHelper(21211): 检测到信标: id1: b9407f90-f5f8-466e-aff9-25556b57fe6d id2: 0 id3: 0
08:54:23.977 D/ScanHelper(21211):寻找此信标的测距区域匹配
08:54:23.994 D/CycledLeScannerForLollipop(21211):获得记录
08:54:23.997 D/BeaconParser(21211):忽略 pdu 类型 01
08:54:23.997 D/BEACONPARSER(21211):处理PDU类型FF:0201061AFF4C000215E9407F30F55F55F55F555555555555700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000099999安州州
【问题讨论】:
标签: android beacon altbeacon android-ibeacon