我正在使用 altbeacon 库 2.15+ 但对于 oreo 和 nougat 版本不是扫描信标?
I am using altbeacon library 2.15+ but for oreo and nougat version is not scanning beacon?
onBeacon ServiceConnect 方法是检测beacon。对于棒棒糖版本正在检测牛轧糖和奥利奥版本信标未检测:
public void onBeaconServiceConnect() {
RangeNotifier rangeNotifier = new RangeNotifier() {
@Override
public void didRangeBeaconsInRegion(Collection<Beacon> beacons, org.altbeacon.beacon.Region region) {
Log.d(TAG, "in didRangeBeaconsInRegion " + beacons.size());
if (beacons.size() > 0) {
Log.d(TAG, "didRangeBeaconsInRegion called with beacon count: " + beacons.size());
for (Iterator<Beacon> iterator = beacons.iterator();
iterator.hasNext(); ) {
Beacon beacon = iterator.next();
if (beaconlist.size() > 0) {
Log.d(TAG, "List Size :" + beaconlist.size());
for (int i = 0; i < beaconlist.size(); i++) {
Log.d("BeaconList ", beaconlist.get(i));
}
}
if (!beaconlist.contains(beacon.getId1().toString())) {
Log.d(TAG,"In get APi");
getApi(beacon.getId1().toString());
beaconlist.add(beacon.getId1().toString());
Log.d(TAG, "Notify in dead state");
Log.d("Notify in dead state", beacon.getId1().toString());
}
}
}
}
};
try {
Log.d(TAG, "I am in startRangingBeaconsInRegion");
beaconManager.startRangingBeaconsInRegion(new Region("myRangingUniqueId", null, null, null));
beaconManager.addRangeNotifier(rangeNotifier);
} catch (RemoteException e) {
e.printStackTrace();
}
}
这是我的代码,任何人都可以解决这个问题。
要检查两件事:
您是否已将 COARSE_LOCATION 权限添加到您的 AndroidManifest.xml 并添加代码以在运行时动态地从用户那里成功获取该权限?
您是否成功构建了 BeaconManager、调用 bind(...) 并确认您在开始测距之前收到了 onBeaconServiceConnect()
的回调?如果不这样做,您将在尝试开始测距时收到 RemoteException。使用 Log.e(TAG, "Not bound to beacon scanning service")
将此异常记录到 LogCat 是个好主意
onBeacon ServiceConnect 方法是检测beacon。对于棒棒糖版本正在检测牛轧糖和奥利奥版本信标未检测: public void onBeaconServiceConnect() {
RangeNotifier rangeNotifier = new RangeNotifier() {
@Override
public void didRangeBeaconsInRegion(Collection<Beacon> beacons, org.altbeacon.beacon.Region region) {
Log.d(TAG, "in didRangeBeaconsInRegion " + beacons.size());
if (beacons.size() > 0) {
Log.d(TAG, "didRangeBeaconsInRegion called with beacon count: " + beacons.size());
for (Iterator<Beacon> iterator = beacons.iterator();
iterator.hasNext(); ) {
Beacon beacon = iterator.next();
if (beaconlist.size() > 0) {
Log.d(TAG, "List Size :" + beaconlist.size());
for (int i = 0; i < beaconlist.size(); i++) {
Log.d("BeaconList ", beaconlist.get(i));
}
}
if (!beaconlist.contains(beacon.getId1().toString())) {
Log.d(TAG,"In get APi");
getApi(beacon.getId1().toString());
beaconlist.add(beacon.getId1().toString());
Log.d(TAG, "Notify in dead state");
Log.d("Notify in dead state", beacon.getId1().toString());
}
}
}
}
};
try {
Log.d(TAG, "I am in startRangingBeaconsInRegion");
beaconManager.startRangingBeaconsInRegion(new Region("myRangingUniqueId", null, null, null));
beaconManager.addRangeNotifier(rangeNotifier);
} catch (RemoteException e) {
e.printStackTrace();
}
}
这是我的代码,任何人都可以解决这个问题。
要检查两件事:
您是否已将 COARSE_LOCATION 权限添加到您的 AndroidManifest.xml 并添加代码以在运行时动态地从用户那里成功获取该权限?
您是否成功构建了 BeaconManager、调用 bind(...) 并确认您在开始测距之前收到了
onBeaconServiceConnect()
的回调?如果不这样做,您将在尝试开始测距时收到 RemoteException。使用Log.e(TAG, "Not bound to beacon scanning service")
将此异常记录到 LogCat 是个好主意