首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Android信标库看不到任何信标

Android信标库看不到任何信标
EN

Stack Overflow用户
提问于 2018-12-11 20:18:12
回答 1查看 825关注 0票数 0

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

代码;

代码语言:javascript
复制
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);
}

我的权限:

代码语言:javascript
复制
<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" />

当像这样强制权限时也是如此;

代码语言:javascript
复制
    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();
        }
    }

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

代码语言:javascript
复制
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专业信标吗?(here)

编辑;

当我在手机上强制删除应用程序时,我看到它确实进入了函数didDetermineStateForRegion和onResume。

代码语言:javascript
复制
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对象为空。

代码语言:javascript
复制
D/BLE: I detected a beacon in the region with namespace id null and instance id: null
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-12-12 05:57:53

通过didDetermineStateForRegion回调,我认为检测到了信标,不是吗?Region和instance声明为null。如果您想要获取信标NameSpace和实例,则需要做range。

来源:How to detect Eddystone-Compatible Beacons

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53724075

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档