Android Beacon Library не видит маяков - PullRequest
0 голосов
/ 11 декабря 2018

Я пытаюсь увидеть (любые) маяки BLE (Eddystone) из моего приложения для Android с помощью библиотеки маяков Android, однако, когда я пытаюсь найти образец кода, найденный здесь , я не могу найти какие-либо маяки.

Код;

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?( здесь )

Edit;

При принудительном удалении приложения на моем телефоне я вижу, что оно действительно вводит функции 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 голосов
/ 12 декабря 2018

По обратному вызову didDetermineStateForRegion, я думаю, маяк был обнаружен, не так ли?Регион и экземпляр были объявлены как нулевые.Если вы хотите получить NameSpace и Inacance, вы должны указать диапазон.

Источник: Как определить Eddystone-совместимые маяки

...