无法使用 android 信标库检测 ibeacon
Unable to detect ibeacon with android beacon library
我无法使用 android 信标库检测 ibeacon 的存在。这是我的代码
BeaconManager beaconManager = BeaconManager.getInstanceForApplication(this);
beaconManager = BeaconManager.getInstanceForApplication(this);
if (beaconManager != null && !beaconManager.isBound(this)) {
beaconManager.getBeaconParsers().add(new BeaconParser().
setBeaconLayout("m:0-3=4c000215,i:4-19,i:20-21,i:22-23,p:24-24"));
beaconManager.bind(this);
并且在onBeaconServiceConnect方法中
public void onBeaconServiceConnect() {
BeaconManager beaconManager = BeaconManager.getInstanceForApplication(this);
beaconManager.setRangeNotifier(new RangeNotifier() {
@Override
public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) {
for (Beacon beacon : beacons) {
Log.i("MainActivity", "I see a beacon that is about "+beacon.getDistance()+" meters away.");
System.out.print("Beacon seen"+ beacon.getId1());
}
}
});
try {
beaconManager.startRangingBeaconsInRegion(new Region("myRangingUniqueId", null, null, null));
} catch (RemoteException e) { }
}
我也在 AndroidManifest.xml
中添加了此权限
<uses-sdk
android:minSdkVersion="18"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
在输出中
16:59:26.571 3571-3571/com.example.kev.altbeacon W/BluetoothCrashResolver: Can't read macs from BluetoothCrashResolverState.txt
04-23 16:59:26.581 3571-3571/com.example.kev.altbeacon W/ModelSpecificDistanceCalculator: Cannot find match for this device. Using default
04-23 16:59:26.581 3571-3571/com.example.kev.altbeacon W/ModelSpecificDistanceCalculator: Cannot find match for this device. Using default
04-23 16:59:26.581 3571-3571/com.example.kev.altbeacon E/MonitoringStatus: Deserialization exception, message: $s
04-23 16:59:26.621 3571-3635/com.example.kev.altbeacon D/libEGL: loaded /vendor/lib64/egl/libGLES_mali.so
04-23 16:59:26.641 3571-3635/com.example.kev.altbeacon D/libEGL: eglInitialize EGLDisplay = 0x7f8787f178
04-23 16:59:26.641 3571-3635/com.example.kev.altbeacon I/OpenGLRenderer: Initialized EGL, version 1.4
04-23 16:59:26.641 3571-3635/com.example.kev.altbeacon D/mali_winsys: new_window_surface returns 0x3000, [1440x2560]-format:1
04-23 16:59:26.651 3571-3571/com.example.kev.altbeacon W/DisplayListCanvas: DisplayListCanvas is started on unbinded RenderNode (without mOwningView)
04-23 16:59:26.651 3571-3635/com.example.kev.altbeacon D/libGLESv1: DTS_GLAPI : DTS is not allowed for Package : com.example.kev.altbeacon
04-23 16:59:26.761 3571-3571/com.example.kev.altbeacon I/InjectionManager: dispatchCreateOptionsMenu :com.example.kev.altbeacon.MainActivity
04-23 16:59:26.761 3571-3571/com.example.kev.altbeacon I/InjectionManager: dispatchPrepareOptionsMenu :com.example.kev.altbeacon.MainActivity
04-23 16:59:26.761 3571-3571/com.example.kev.altbeacon D/ViewRootImpl: MSG_RESIZED_REPORT: ci=Rect(0, 96 - 0, 0) vi=Rect(0, 96 - 0, 0) or=1
04-23 16:59:26.791 3571-3571/com.example.kev.altbeacon I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@bf0208c time:27543539
04-23 16:59:27.881 3571-3571/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-23 16:59:27.881 3571-3571/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-23 16:59:27.881 3571-3571/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-23 16:59:27.881 3571-3571/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-23 16:59:27.881 3571-3571/com.example.kev.altbeacon D/BluetoothLeScanner: could not find callback wrapper
04-23 16:59:28.991 3571-3571/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-23 16:59:28.991 3571-3571/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-23 16:59:28.991 3571-3571/com.example.kev.altbeacon D/BluetoothLeScanner: could not find callback wrapper
04-23 16:59:30.101 3571-3571/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-23 16:59:30.101 3571-3571/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-23 16:59:30.101 3571-3571/com.example.kev.altbeacon D/BluetoothLeScanner: could not find callback wrapper
04-23 16:59:31.241 3571-3571/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
我用两部不同的手机尝试了该代码,但它对其中任何一部都不起作用。这个输出是我用三星 S6 尝试代码时的结果。使用 Samsung s4 我没有得到这个状态-好的/找不到...消息,我只得到这个
04-23 17:09:22.290 26020-26020/com.example.kev.altbeacon I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@1034a987 time:6819065
04-23 17:09:36.083 26020-26020/com.example.kev.altbeacon V/ActivityThread: updateVisibility : ActivityRecord{1a3840b9 token=android.os.BinderProxy@1034a987 {com.example.kev.altbeacon/com.example.kev.altbeacon.MainActivity}} show : true
几点提示:
如果您的设备 Android 6+,您必须确保您已获得位置权限,如下所述:http://developer.radiusnetworks.com/2015/09/29/is-your-beacon-app-ready-for-android-6.html
尝试使用相同库的现成 Locate app。如果该应用无法检测到信标,则可能是信标发射器本身存在问题。
确保在“设置”中打开“定位”。
确保蓝牙已在“设置”中打开。
我无法使用 android 信标库检测 ibeacon 的存在。这是我的代码
BeaconManager beaconManager = BeaconManager.getInstanceForApplication(this);
beaconManager = BeaconManager.getInstanceForApplication(this);
if (beaconManager != null && !beaconManager.isBound(this)) {
beaconManager.getBeaconParsers().add(new BeaconParser().
setBeaconLayout("m:0-3=4c000215,i:4-19,i:20-21,i:22-23,p:24-24"));
beaconManager.bind(this);
并且在onBeaconServiceConnect方法中
public void onBeaconServiceConnect() {
BeaconManager beaconManager = BeaconManager.getInstanceForApplication(this);
beaconManager.setRangeNotifier(new RangeNotifier() {
@Override
public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) {
for (Beacon beacon : beacons) {
Log.i("MainActivity", "I see a beacon that is about "+beacon.getDistance()+" meters away.");
System.out.print("Beacon seen"+ beacon.getId1());
}
}
});
try {
beaconManager.startRangingBeaconsInRegion(new Region("myRangingUniqueId", null, null, null));
} catch (RemoteException e) { }
}
我也在 AndroidManifest.xml
中添加了此权限<uses-sdk
android:minSdkVersion="18"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
在输出中
16:59:26.571 3571-3571/com.example.kev.altbeacon W/BluetoothCrashResolver: Can't read macs from BluetoothCrashResolverState.txt
04-23 16:59:26.581 3571-3571/com.example.kev.altbeacon W/ModelSpecificDistanceCalculator: Cannot find match for this device. Using default
04-23 16:59:26.581 3571-3571/com.example.kev.altbeacon W/ModelSpecificDistanceCalculator: Cannot find match for this device. Using default
04-23 16:59:26.581 3571-3571/com.example.kev.altbeacon E/MonitoringStatus: Deserialization exception, message: $s
04-23 16:59:26.621 3571-3635/com.example.kev.altbeacon D/libEGL: loaded /vendor/lib64/egl/libGLES_mali.so
04-23 16:59:26.641 3571-3635/com.example.kev.altbeacon D/libEGL: eglInitialize EGLDisplay = 0x7f8787f178
04-23 16:59:26.641 3571-3635/com.example.kev.altbeacon I/OpenGLRenderer: Initialized EGL, version 1.4
04-23 16:59:26.641 3571-3635/com.example.kev.altbeacon D/mali_winsys: new_window_surface returns 0x3000, [1440x2560]-format:1
04-23 16:59:26.651 3571-3571/com.example.kev.altbeacon W/DisplayListCanvas: DisplayListCanvas is started on unbinded RenderNode (without mOwningView)
04-23 16:59:26.651 3571-3635/com.example.kev.altbeacon D/libGLESv1: DTS_GLAPI : DTS is not allowed for Package : com.example.kev.altbeacon
04-23 16:59:26.761 3571-3571/com.example.kev.altbeacon I/InjectionManager: dispatchCreateOptionsMenu :com.example.kev.altbeacon.MainActivity
04-23 16:59:26.761 3571-3571/com.example.kev.altbeacon I/InjectionManager: dispatchPrepareOptionsMenu :com.example.kev.altbeacon.MainActivity
04-23 16:59:26.761 3571-3571/com.example.kev.altbeacon D/ViewRootImpl: MSG_RESIZED_REPORT: ci=Rect(0, 96 - 0, 0) vi=Rect(0, 96 - 0, 0) or=1
04-23 16:59:26.791 3571-3571/com.example.kev.altbeacon I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@bf0208c time:27543539
04-23 16:59:27.881 3571-3571/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-23 16:59:27.881 3571-3571/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-23 16:59:27.881 3571-3571/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-23 16:59:27.881 3571-3571/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-23 16:59:27.881 3571-3571/com.example.kev.altbeacon D/BluetoothLeScanner: could not find callback wrapper
04-23 16:59:28.991 3571-3571/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-23 16:59:28.991 3571-3571/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-23 16:59:28.991 3571-3571/com.example.kev.altbeacon D/BluetoothLeScanner: could not find callback wrapper
04-23 16:59:30.101 3571-3571/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-23 16:59:30.101 3571-3571/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
04-23 16:59:30.101 3571-3571/com.example.kev.altbeacon D/BluetoothLeScanner: could not find callback wrapper
04-23 16:59:31.241 3571-3571/com.example.kev.altbeacon D/BluetoothAdapter: STATE_ON
我用两部不同的手机尝试了该代码,但它对其中任何一部都不起作用。这个输出是我用三星 S6 尝试代码时的结果。使用 Samsung s4 我没有得到这个状态-好的/找不到...消息,我只得到这个
04-23 17:09:22.290 26020-26020/com.example.kev.altbeacon I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@1034a987 time:6819065
04-23 17:09:36.083 26020-26020/com.example.kev.altbeacon V/ActivityThread: updateVisibility : ActivityRecord{1a3840b9 token=android.os.BinderProxy@1034a987 {com.example.kev.altbeacon/com.example.kev.altbeacon.MainActivity}} show : true
几点提示:
如果您的设备 Android 6+,您必须确保您已获得位置权限,如下所述:http://developer.radiusnetworks.com/2015/09/29/is-your-beacon-app-ready-for-android-6.html
尝试使用相同库的现成 Locate app。如果该应用无法检测到信标,则可能是信标发射器本身存在问题。
确保在“设置”中打开“定位”。
确保蓝牙已在“设置”中打开。