添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

Android信标库看不到任何信标

内容来源于 Stack Overflow,遵循 CC BY-SA 4.0 许可协议进行翻译与使用。IT领域专用引擎提供翻译支持

腾讯云小微IT领域专用引擎提供翻译支持

原文
Stack Overflow用户 修改于2018-12-11
  • 该问题已被编辑
  • 提问者: Stack Overflow用户
  • 提问时间: 2018-12-11 20:18

我正在尝试使用安卓信标库从我的安卓应用程序中查看(任何) 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专业信标吗?( 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