umair13adil / simple_beacons_flutter

A flutter plugin project to range & monitor iBeacons.
Apache License 2.0
35 stars 42 forks source link

Background activity crashes after 1min on Android #31

Closed LeaBuchweitz closed 3 years ago

LeaBuchweitz commented 3 years ago

Hi again!

I have enabled the background activity, but after ~1min the monitoring process crashes, with the log saying

---> D/BeaconHelper(14193): didExitRegion I/ScanJob (14193): Using immediateScanJobId from manifest: 208352939 I/ScanJob (14193): Using periodicScanJobId from manifest: 208352940 W/JobInfo (14193): Specified interval for 208352940 is +5m0s0ms. Clamped to +15m0s0ms W/JobInfo (14193): Specified flex for 208352940 is 0. Clamped to +5m0s0ms W/JobInfo (14193): Specified interval for 208352940 is +5m0s0ms. Clamped to +15m0s0ms W/JobInfo (14193): Specified flex for 208352940 is 0. Clamped to +5m0s0ms I/ScanJob (14193): Using periodicScanJobId from manifest: 208352940 I/ScanJob (14193): onStopJob called for immediate scan org.altbeacon.beacon.service.ScanJob@1c46f94 D/BluetoothAdapter(14193): isLeEnabled(): ON D/BluetoothAdapter(14193): isLeEnabled(): ON D/BluetoothAdapter(14193): isLeEnabled(): ON D/BluetoothLeScanner(14193): could not find callback wrapper D/BluetoothAdapter(14193): isLeEnabled(): ON I/CycledLeScanner(14193): Using Android O scanner I/ScanJob (14193): Using immediateScanJobId from manifest: 208352939 I/ScanJob (14193): Running immediate scan job: instance is org.altbeacon.beacon.service.ScanJob@1750e8 I/ScanJob (14193): scanJob version 2.16.4 is starting up on the main process W/ModelSpecificDistanceCalculator(14193): Cannot find match for this device. Using default W/ModelSpecificDistanceCalculator(14193): Cannot find match for this device. Using default D/BluetoothAdapter(14193): isLeEnabled(): ON I/ScanJob (14193): Scan job running for 300000 millis D/BluetoothAdapter(14193): isLeEnabled(): ON D/BluetoothLeScanner(14193): onScannerRegistered() - status=0 scannerId=6 mScannerId=0 I/BluetoothLeScanner(14193): start scan is blocked E/CycledLeScannerForLollipop(14193): Scan failed: app cannot be registered <----

I've done some research and found some suggestions here: link Unfortunately, none of the offered fixes helped.

I really appreciate your help! Thanks in advance and best regards, Lea

LeaBuchweitz commented 3 years ago

I have looked into it again and it seems that this does only happen when leaving the application for the first time. After approx. 1 min didExitRegion (first line of the log above) is called and the app stops monitoring for beacons. You need to bring the application to the foreground again for the monitoring process to continue. If you leave the application again it crashes again after 1min, but restores the monitoring process without problems (by calling didEnterRegion after didExitRegion, which is not called at the first time).

I've tried it with your example and my own app an the behavior is the same: After leaving the application for the first time, it crashes after 1 min., you need to bring the app to the foreground again and it never happens again.

May it be possible that some initialization is missing? I would really appreciate your help :) Best, Lea

LeaBuchweitz commented 3 years ago

After trying out several code snippets on different devices, I have figured out the problem. In case anyone stumbles upon a similar problem, here is how I solved it:

Best regards, Lea