Android信标库看不到任何信标

时间:2018-12-11 12:18:12

标签: android bluetooth-lowenergy altbeacon

我正在尝试使用Android Beacon库从我的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

为什么我看不到我的信标?使用“定位”之类的应用时,我可以看到它们。是因为我正在使用SENSORO SmartBeacon-4AA Pro信标吗? (here

编辑;

在手机上强行删除应用程序时,我看到它确实输入了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对象为null。

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

1 个答案:

答案 0 :(得分:0)

通过didDetermineStateForRegion回调,我认为检测到了信标,不是吗? Region和instance声明为null。如果要获取信标命名空间和实例,则应进行范围设置。

来源:How to detect Eddystone-Compatible Beacons

相关问题