Android 信标库没有看到任何信标

Android Beacon Library not seeing any beacons

我正在尝试使用 Android 信标库从我的 android 应用程序中查看(任何)BLE 信标 (Eddystone),但是当我尝试找到示例代码时 here 我我找不到任何信标。

代码;

public void onResume() {
    super.onResume();
    mBeaconManager = BeaconManager.getInstanceForApplication(this.getApplicationContext());
    // Detect the main Eddystone-UID frame:
    mBeaconManager.getBeaconParsers().add(new BeaconParser().
            setBeaconLayout(BeaconParser.EDDYSTONE_UID_LAYOUT));
    mBeaconManager.bind(this);
    Log.d(TAG, "Inside onResume");
}

@Override
public void onBeaconServiceConnect() {
    // Set the two identifiers below to null to detect any beacon regardless of identifiers
    Identifier myBeaconNamespaceId = null;
    Identifier myBeaconInstanceId = null;
    Region region = new Region("my-beacon-region", myBeaconNamespaceId, myBeaconInstanceId, null);
    mBeaconManager.addMonitorNotifier(this);
    try {
        mBeaconManager.startMonitoringBeaconsInRegion(region);
    } catch (RemoteException e) {
        e.printStackTrace();
    }
}

public void didEnterRegion(Region region) {
    Log.d(TAG, "I detected a beacon in the region with namespace id " + region.getId1() +
            " and instance id: " + region.getId2());
}

public void didExitRegion(Region region) {
    Log.d(TAG, "Inside didExitRegion");
}

public void didDetermineStateForRegion(int state, Region region) {
    Log.d(TAG, "Inside DidtermineStateForRegion");
}

@Override
public void onPause() {
    super.onPause();
    mBeaconManager.unbind(this);
}

我的权限:

<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

也像这样强制权限时;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { // Android M Permission check
        if (this.checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
            final AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle("This app needs location access");
            builder.setMessage("Please grant location access so this app can detect beacons.");
            builder.setPositiveButton(android.R.string.ok, null);
            builder.setOnDismissListener(new DialogInterface.OnDismissListener() {
                @Override
                public void onDismiss(DialogInterface dialog) {
                    requestPermissions(new String[]{Manifest.permission.ACCESS_COARSE_LOCATION}, PERMISSION_REQUEST_COARSE_LOCATION);
                }
            });
            builder.show();
        }
    }

我在日志中没有得到任何结果。我收到的唯一日志是;

I/CycledLeScanner: Using Android O scanner
I/ScanJob: Using immediateScanJobId from manifest: 208352939
    Running immediate scan job: instance is org.altbeacon.beacon.service.ScanJob@35cea01
I/ScanJob: scanJob version 2.15.2 is starting up on the main process
W/ModelSpecificDistanceCalculator: Cannot find match for this device.  Using default
    Cannot find match for this device.  Using default
D/BluetoothAdapter: isLeEnabled(): ON
I/ScanJob: Scan job running for 300000 millis
D/BluetoothAdapter: isLeEnabled(): ON
D/BluetoothLeScanner: onScannerRegistered() - status=0 scannerId=10 mScannerId=0
I/ScanHelper: Non-distinct packets detected in a single scan.  Restarting scans unecessary.
I/zygote64: Do full code cache collection, code=124KB, data=96KB
I/zygote64: After code cache collection, code=100KB, data=60KB
I/zygote64: Do partial code cache collection, code=122KB, data=75KB
I/zygote64: After code cache collection, code=122KB, data=75KB
    Increasing code cache capacity to 512KB

为什么我看不到我的信标?当使用像 Locate 这样的应用程序时,我能够看到它们。是因为我使用的是 SENSORO SmartBeacon-4AA Pro 信标吗? (here)

编辑;

在我的 phone 上强行删除应用程序时,我看到它确实进入了函数 didDetermineStateForRegion 和 onResume。

I/ScanJob: Scan job running for 300000 millis
I/Choreographer: Skipped 30 frames!  The application may be doing too much work on its main thread.
I/ModelSpecificDistanceCalculator: Successfully saved new distance model file
W/ModelSpecificDistanceCalculator: Cannot find match for this device.  Using default
I/ModelSpecificDistanceCalculator: Successfully updated distance model with latest from online database
D/OpenGLRenderer: endAllActiveAnimators on 0x782e321000 (RippleDrawable) with handle 0x782d1cff40
I/BeaconManager: Cancelling scheduled jobs after unbind of last consumer.
I/ScanJob: Using immediateScanJobId from manifest: 208352939
I/ScanJob: Using periodicScanJobId from manifest: 208352940
I/ScanJob: Using periodicScanJobId from manifest: 208352940
    onStopJob called for immediate scan org.altbeacon.beacon.service.ScanJob@ccab959
D/BluetoothAdapter: isLeEnabled(): ON
D/BluetoothLeScanner: could not find callback wrapper
D/BluetoothAdapter: isLeEnabled(): ON
D/BluetoothLeScanner: could not find callback wrapper
D/BluetoothAdapter: isLeEnabled(): ON
D/BLE: coarse location permission granted
D/BeaconParser: Parsing beacon layout: s:0-1=feaa,m:2-2=00,p:3-3:-41,i:4-13,i:14-19
I/zygote64: Do full code cache collection, code=124KB, data=98KB
I/zygote64: After code cache collection, code=101KB, data=55KB
I/ScanJob: Using immediateScanJobId from manifest: 208352939
I/ScanJob: Using periodicScanJobId from manifest: 208352940
W/JobInfo: Specified interval for 208352940 is +5m0s0ms. Clamped to +15m0s0ms
    Specified flex for 208352940 is 0. Clamped to +5m0s0ms
W/JobInfo: Specified interval for 208352940 is +5m0s0ms. Clamped to +15m0s0ms
    Specified flex for 208352940 is 0. Clamped to +5m0s0ms
D/BLE: Inside DidtermineStateForRegion
    Inside onResume
I/CycledLeScanner: Using Android O scanner
I/ScanJob: Using immediateScanJobId from manifest: 208352939
I/ScanJob: Running immediate scan job: instance is org.altbeacon.beacon.service.ScanJob@9fcab08
I/ScanJob: scanJob version 2.15.2 is starting up on the main process
W/ModelSpecificDistanceCalculator: Cannot find match for this device.  Using default
W/ModelSpecificDistanceCalculator: Cannot find match for this device.  Using default
D/BluetoothAdapter: isLeEnabled(): ON
I/ScanJob: Scan job running for 300000 millis
D/BluetoothAdapter: isLeEnabled(): ON
D/BluetoothLeScanner: onScannerRegistered() - status=0 scannerId=10 mScannerId=0
I/ScanHelper: Non-distinct packets detected in a single scan.  Restarting scans unecessary.
I/zygote64: Do partial code cache collection, code=113KB, data=76KB
I/zygote64: After code cache collection, code=113KB, data=76KB
    Increasing code cache capacity to 512KB

当在 didDetermineStateForRegion 内部时,Region 对象为空。

D/BLE: I detected a beacon in the region with namespace id null and instance id: null

通过 didDetermineStateForRegion 回调,我认为检测到了信标,不是吗?区域和实例被声明为空。如果你想获得信标命名空间和实例,你应该做范围。

来源:How to detect Eddystone-Compatible Beacons