0

I am currently using https://github.com/AltBeacon/android-beacon-library to detect iBeacon in app in service.

In my application, scan restart is performed every 6 seconds, and the monitoring cycle is set as follows.

beaconManager.setForegroundBetweenScanPeriod(0);
beaconManager.setForegroundScanPeriod(1100);    // 1 second interval for group of measurements
beaconManager.setBackgroundBetweenScanPeriod(beaconManager.getForegroundBetweenScanPeriod());    // // set background same as foreground
beaconManager.setBackgroundScanPeriod(beaconManager.getForegroundScanPeriod());

Then the monitoring checks the region according to the didDetermineStateForRegion state.

public void startMonitoringBeaconsInRegion() {
    if (beaconConsumer == null
            || !beaconManager.isBound(beaconConsumer)) {

        Log.w(TAG, "Method startMonitoringBeaconsInRegion() invocation will be ignored.");

        return;
    }

    refreshMode();

    beaconManager.setNonBeaconLeScanCallback(this::nonBeaconLeScanCallback);
    beaconManager.removeAllMonitorNotifiers();
    beaconManager.addMonitorNotifier(new MonitorNotifier() {
        @Override
        public void didEnterRegion(Region region) {
            Log.i(TAG, "Did Enter Region");
        }

        @Override
        public void didExitRegion(Region region) {
            Log.i(TAG, "Did Exit Region");
            isAdvertisingRefresh = true;
        }

        @Override
        public void didDetermineStateForRegion(int state, Region region) {
            Log.i(TAG, "Did Determine State For Region");
            try {
                switch (state) {
                    case MonitorNotifier.INSIDE:
                        countContinueDetected_E_Beacon = 0;
                        countNotDetectedBeaconForStopAdv = 0;

                        Log.i(TAG, "INSIDE, Ranging is started");

                        beaconManager.startRangingBeaconsInRegion(region);
                        break;

                    case MonitorNotifier.OUTSIDE:
                        Log.i(TAG, "OUTSIDE, Ranging is stopped");
                        beaconManager.stopRangingBeaconsInRegion(region);

                        stopDoorOpenAdvertising();
                        break;
                }
            } catch (RemoteException e) {
                e.printStackTrace();
                unbind();
                bind();
            }
        }
    });

    beaconManager.removeAllRangeNotifiers();
    beaconManager.addRangeNotifier((beacons, region) -> didRangeBeacons(beacons));

    try {
        beaconManager.startMonitoringBeaconsInRegion(mRegion);

        isMonitoringBeaconsInRegion = true;
    } catch (RemoteException e) {
        e.printStackTrace();
        unbind();
        bind();
    }


    Log.i(TAG, "Monitoring is started");
}

After running the application, monitoring starts and the corresponding message appears after a certain period of time.

enter image description here

Why do these messages keep appearing? Is there any way to get rid of it?

In addition to this, when launching the app, it keeps telling me that a BLE scan with the same settings has already been started in the app.

enter image description here

We are using BluetoothMedic in our application and we only monitor if monitoring is not started.

Please let me know how we can improve these issues as well. Thank you.

bnnnw154
  • 23
  • 3

1 Answers1

1

Both of those log lines are output by the Android operating system as a result of your application running, and neither indicate a problem.

  • The first indicates a garbage collection cycle is running to clean up unused memory. This is normal for any Android program.

  • The second indicates that two parts of your program are starting an identical Bluetooth scans at the same time, so the most recent scan start is ignored. This happens if you are using BluetoothMedic at the same time as ranging or monitoring. This is expected and normal when using BluetoothMedic because the scans sometimes overlap. The Android OS outputs that log line, and it has no negative consequences.

When building with third party software (the Android OS and the Android Beacon Library in this case) you must accept that the dependent software will do its own logging based on choices of the original author and you will have little control over it.

Since it is not realistic to build everything yourself just to gain total control over logging, the best thing to do is just accept the logging that happens and focus your energy on making the code you do control work as well as possible.

davidgyoung
  • 63,876
  • 14
  • 121
  • 204
  • During monitoring, if it is outside, stopRanging is executed and if it is inside, startRanging is executed. If the garbage execution log continues to appear, a problem is found that the monitoring notification does not proceed normally. This symptom disappears after rebooting the phone. So far I haven't had any issues reappearing after reboot. Does continuous monitoring cause this problem even when the application is not used? – bnnnw154 Aug 17 '22 at 04:28
  • I would suggest adding custom Log.d statements for every event that your app processes to see what steps it did before monitoring events stop firing. Always be sure to add log statements in catch clauses so you know if exceptions happen. When debugging, the more logging the better. Focus first on your app’s custom logs and not OS or third party logs. – davidgyoung Aug 17 '22 at 15:07