petermetz / cordova-plugin-ibeacon

An iBeacon plugin for Phonegap / Cordova 3.x and upwards. Supports both iOS and Android (contributions are welcome)
Apache License 2.0
730 stars 372 forks source link

... keep monitoring/ranging when app is killed (android) #335

Open sapienzafra opened 6 years ago

sapienzafra commented 6 years ago

Even though others have already asked on this topic (#71, #259, #274), I still haven't understand if is it possible to keep monitoring/ranging beacons once the Android app has been killed (ionic). Background monitoring works fine (tested on android 4.4 and 7.1), but what I need is a permanent scan, even when the app is killed, to log region entries via an http request. No need to launch again the app or interact with it. Someone says the trick is to create a sticky service in which all relevant functionality are natively executed. Should I keep trying in that direction? I'm new in ionic, cordova and app developing in general. Thanks.

ugurerkan commented 6 years ago

I have also issues with this situation, there is locate beacon app from RadiusNetworks it performs well when monitoring beacon app not running background or foreground.

Trying to monitor region then when entered, start ranging with that beacon. But, plugin detects region after ~10-30 second however locate beacon app notice in between 1-3 second.

Is there anything missed?

global packages:
    cordova (Cordova CLI) : 7.1.0

local packages:
    Cordova Platforms  : android 6.3.0 ios 4.5.3
    Ionic Framework    : ionic-angular 3.8.0

System:
    ios-deploy : 1.9.2
    ios-sim    : 6.1.2
    Node       : v8.9.3
    npm        : 5.6.0
    OS         : macOS Sierra
    Xcode      : Xcode 9.2 Build version 9C40b
sapienzafra commented 6 years ago

@ugurerkan thank you for reply! That plugin looks good but (if I understand well) they want you to sign up to their service for free or pay monthly if you have more than 3 beacons. I would like to build a standalone app without relying on other's services. Thanks again!

petermetz commented 6 years ago

@sapienzafra

Can you try reproducing your issue with the quickstart app? https://github.com/petermetz/cordova-proximity-quickstart

Peter

florent1933 commented 6 years ago

I have the same problem on android (android 8), I can't monitor the beacon when the app is killed but it works on background.

I tried to reproduce the issue with the quickstart app but it's crashing when I tap on Start

This is the adb's log:

1-04 09:40:36.316  1143  1143 D SystemWebChromeClient: http://192.168.1.10:8101/__ion-dev-server/ion-dev.js?v=2.1.3: Line 156 : Creating BeaconRegion with UUID of: 
01-04 09:40:36.317  1143  1143 I chromium: [INFO:CONSOLE(156)] "Creating BeaconRegion with UUID of: ", source: http://192.168.1.10:8101/__ion-dev-server/ion-dev.js?v=2.1.3 (156)
01-04 09:40:36.326  1143  1283 D BeaconManager: callback packageName: com.unarin.oss.mobile.CordovaProximityQuickstart
01-04 09:40:36.338 24586 24586 I PhenotypeExpConfig: refreshConfiguration() : Force = false : UpdateAvailable = false : Age = 3 minutes : MaxAge = 720 minutes
01-04 09:40:36.339 24586 24586 I LatinIme: abortComposing()
01-04 09:40:36.341 24586 24586 I Delight5Decoder: abortComposing() : input state id = 3168
01-04 09:40:36.341 24586 24586 I LatinIme: onDeactivate()
01-04 09:40:36.342 24586 24586 I EmojiDataExtension: onDeactivate() : Locale = fr
01-04 09:40:36.342 24586 24586 I GifEntryExtension: onDeactivate()
01-04 09:40:36.344 24586 28375 W Delight5Decoder: removePredictionEngine() : Unknown engine bzr@7f5d95
01-04 09:40:36.344 24586 24586 I GoogleInputMethod: onStartInput() : Dummy InputConnection bound
01-04 09:40:36.373  1143  1283 D MonitoringStatus: Restored region monitoring state for 1 regions.
01-04 09:40:36.374  1143  1283 D MonitoringStatus: Region  id1: 00000000-0000-0000-0000-000000000000 id2: 1 id3: 1 uniqueId: nullBeaconRegion state: org.altbeacon.beacon.service.RegionMonitoringState@95b8bdf
01-04 09:40:36.375  1143  1283 D MonitoringStatus: Done restoring monitoring status
01-04 09:40:36.375  1143  1283 D MonitoringStatus: Replacing region with unique identifier nullBeaconRegion
01-04 09:40:36.376  1143  1283 D MonitoringStatus: Old definition: id1: 00000000-0000-0000-0000-000000000000 id2: 1 id3: 1
01-04 09:40:36.377  1143  1283 D MonitoringStatus: New definition: id1: 00000000-0000-0000-0000-000000000001 id2: 1 id3: 1
01-04 09:40:36.377  1143  1283 D MonitoringStatus: clearing state
01-04 09:40:36.377  1143  1283 D MonitoringStatus: saveMonitoringStatusIfOn()
01-04 09:40:36.390  1143  1283 D ScanJobScheduler: Applying settings to ScanJob
01-04 09:40:36.481  1143  1283 D ScanState: Scan state restore regions: monitored=1 ranged=1
01-04 09:40:36.482  1143  1283 D ScanState: ranged regions: old=1 new=0
01-04 09:40:36.482  1143  1283 D ScanState: monitored regions: old=1 new=1
01-04 09:40:36.483  1143  1283 D ScanState: Stopping ranging region: id1: 00000000-0000-0000-0000-000000000000 id2: 1 id3: 1
01-04 09:40:36.483  1143  1283 D ScanState: Updated state with 0 ranging regions and 1 monitoring regions.
01-04 09:40:36.506  1143  1283 D ScanState: Temp file is /data/user/0/com.unarin.oss.mobile.CordovaProximityQuickstart/files/android-beacon-library-scan-state-temp
01-04 09:40:36.507  1143  1283 D ScanState: Perm file is /data/user/0/com.unarin.oss.mobile.CordovaProximityQuickstart/files/android-beacon-library-scan-state
01-04 09:40:36.507  1143  1283 D MonitoringStatus: saveMonitoringStatusIfOn()
01-04 09:40:36.512  1143  1283 D ScanJobScheduler: Applying scan job settings with background mode false
01-04 09:40:36.513  1143  1283 D BeaconLocalBroadcastProcessor: Register calls: global=1 instance=1
01-04 09:40:36.516  1143  1323 D ScanJobScheduler: Applying settings to ScanJob
01-04 09:40:36.518  1143  1283 E AndroidRuntime: FATAL EXCEPTION: AsyncTask #3
01-04 09:40:36.518  1143  1283 E AndroidRuntime: Process: com.unarin.oss.mobile.CordovaProximityQuickstart, PID: 1143
01-04 09:40:36.518  1143  1283 E AndroidRuntime: java.lang.RuntimeException: An error occurred while executing doInBackground()
01-04 09:40:36.518  1143  1283 E AndroidRuntime:    at android.os.AsyncTask$3.done(AsyncTask.java:353)
01-04 09:40:36.518  1143  1283 E AndroidRuntime:    at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
01-04 09:40:36.518  1143  1283 E AndroidRuntime:    at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
01-04 09:40:36.518  1143  1283 E AndroidRuntime:    at java.util.concurrent.FutureTask.run(FutureTask.java:271)
01-04 09:40:36.518  1143  1283 E AndroidRuntime:    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
01-04 09:40:36.518  1143  1283 E AndroidRuntime:    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
01-04 09:40:36.518  1143  1283 E AndroidRuntime:    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
01-04 09:40:36.518  1143  1283 E AndroidRuntime:    at java.lang.Thread.run(Thread.java:764)
01-04 09:40:36.518  1143  1283 E AndroidRuntime: Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/content/LocalBroadcastManager;
01-04 09:40:36.518  1143  1283 E AndroidRuntime:    at org.altbeacon.beacon.BeaconLocalBroadcastProcessor.unregister(BeaconLocalBroadcastProcessor.java:82)
01-04 09:40:36.518  1143  1283 E AndroidRuntime:    at org.altbeacon.beacon.BeaconLocalBroadcastProcessor.register(BeaconLocalBroadcastProcessor.java:74)
01-04 09:40:36.518  1143  1283 E AndroidRuntime:    at org.altbeacon.beacon.service.ScanJobScheduler.ensureNotificationProcessorSetup(ScanJobScheduler.java:69)
01-04 09:40:36.518  1143  1283 E AndroidRuntime:    at org.altbeacon.beacon.service.ScanJobScheduler.schedule(ScanJobScheduler.java:122)
01-04 09:40:36.518  1143  1283 E AndroidRuntime:    at org.altbeacon.beacon.service.ScanJobScheduler.applySettingsToScheduledJob(ScanJobScheduler.java:85)
01-04 09:40:36.518  1143  1283 E AndroidRuntime:    at org.altbeacon.beacon.service.ScanJobScheduler.applySettingsToScheduledJob(ScanJobScheduler.java:92)
01-04 09:40:36.518  1143  1283 E AndroidRuntime:    at org.altbeacon.beacon.BeaconManager.applyChangesToServices(BeaconManager.java:962)
01-04 09:40:36.518  1143  1283 E AndroidRuntime:    at org.altbeacon.beacon.BeaconManager.startMonitoringBeaconsInRegion(BeaconManager.java:902)
01-04 09:40:36.518  1143  1283 E AndroidRuntime:    at com.unarin.cordova.beacon.LocationManager$16.run(LocationManager.java:832)
01-04 09:40:36.518  1143  1283 E AndroidRuntime:    at com.unarin.cordova.beacon.LocationManager$33.doInBackground(LocationManager.java:1433)
01-04 09:40:36.518  1143  1283 E AndroidRuntime:    at com.unarin.cordova.beacon.LocationManager$33.doInBackground(LocationManager.java:1427)
01-04 09:40:36.518  1143  1283 E AndroidRuntime:    at android.os.AsyncTask$2.call(AsyncTask.java:333)
01-04 09:40:36.518  1143  1283 E AndroidRuntime:    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
01-04 09:40:36.518  1143  1283 E AndroidRuntime:    ... 4 more
01-04 09:40:36.518  1143  1283 E AndroidRuntime: Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.content.LocalBroadcastManager" on path: DexPathList[[zip file "/data/app/com.unarin.oss.mobile.CordovaProximityQuickstart-_Nt90XGtYR6ChNzg5V-b_g==/base.apk"],nativeLibraryDirectories=[/data/app/com.unarin.oss.mobile.CordovaProximityQuickstart-_Nt90XGtYR6ChNzg5V-b_g==/lib/arm64, /system/lib64, /system/vendor/lib64]]
01-04 09:40:36.518  1143  1283 E AndroidRuntime:    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:93)
01-04 09:40:36.518  1143  1283 E AndroidRuntime:    at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
01-04 09:40:36.518  1143  1283 E AndroidRuntime:    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
01-04 09:40:36.518  1143  1283 E AndroidRuntime:    ... 17 more
01-04 09:40:36.524  1572  3160 W ActivityManager:   Force finishing activity com.unarin.oss.mobile.CordovaProximityQuickstart/.MainActivity
01-04 09:40:36.525  1572  3160 D ActivityTrigger: ActivityTrigger activityPauseTrigger 
01-04 09:40:36.527  1143  1143 D CordovaActivity: Paused the activity.
01-04 09:40:36.528  1572  1687 I ActivityManager: Showing crash dialog for package com.unarin.oss.mobile.CordovaProximityQuickstart u0
01-04 09:40:36.535  1572  3202 D ActivityTrigger: activityResumeTrigger: The activity in ApplicationInfo{746efc4 com.android.launcher3} is now in focus and seems to be in full-screen mode

Best regard,

Florent

petermetz commented 6 years ago

@florent1933 The quickstart app may not be upgraded to the latest version of the plugin yet (that's in progress). Can you double check if this crash happens after you upgraded the plugin version to the current latest? (v3.6.0) That version should have the latest AltBeacon library which should solve the crash on Android 8. Lot of shoulds and ifs, but let's see.

florent1933 commented 6 years ago

I check with the version v3.6.0 and it continues to crash.

This app https://play.google.com/store/apps/details?id=com.wistiki.android&hl=en which use Ibeacon technology (I believe) is crashing too.

But monitoring iBeacon with your plugin is working in my app. I don't know what's the difference between the quickstart app and mine.

petermetz commented 6 years ago

Note to self: double check if the dependencies are configured properly in the quickstart project.

florent1933 commented 6 years ago

I think they are configured properly. 3.6.0 instead of 3.5.2.

Le 4 janv. 2018 23:10, "Peter Somogyvari" notifications@github.com a écrit :

Note to self: double check if the dependencies are configured properly in the quickstart project.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/petermetz/cordova-plugin-ibeacon/issues/335#issuecomment-355413461, or mute the thread https://github.com/notifications/unsubscribe-auth/ADxla1ATjniifycjhb8xUHVS2Nk0HJr0ks5tHUxIgaJpZM4RArvo .

petermetz commented 6 years ago

Sorry @florent1933 I did not mean the dependency declaration of the plugin itself, but the dependencies of the plugin:

What about the Android v4 support jar lib? It looks like it's not on the class path but it should be.

https://developer.android.com/topic/libraries/support-library/index.html

I don't really get why would one of the oldest support libs be necessary on the newest Android, but still, it wants it on the class path and it doesn't seem to be there. So maybe something is wrong with the generated gradle build files.

florent1933 commented 6 years ago

I am sorry @petermetz, I don't know how to do it. I am not android developper so it's very abstract to me.

petermetz commented 6 years ago

@florent1933 No worries, I'll get there eventually. It's likely either some dependency issue within the quickstart project, or a bug within the AltBeacon library itself (which I doubt because their issue tracker doesn't list anything like this for Android 8)

sapienzafra commented 6 years ago

@petermetz hello, the quickstart app works fine when the app is open or in background. I'm looking for a way to keep monitoring beacons also when the app is killed (swiped away). That's my logcat right before swiping away the app:

D/Callback(14930): attempting callback via global broadcast intent: ComponentInfo{com.unarin.oss.mobile.CordovaProximityQuickstart/org.altbeacon.beacon.BeaconIntentProcessor}
D/com.unarin.beacon(14930): didRangeBeacons: {"region":{"typeName":"BeaconRegion","uuid":"14a123rd-26b6-4d40-b14e-de3223io4nio2t","minor":"62401","identifier":"nullBeaconRegion","major":"2"},"beacons":[],"eventType":"didRangeBeaconsInRegion"}
D/com.unarin.beacon(14930): [DOM] _onDelegateCallback() {"region":{"typeName":"BeaconRegion","uuid":"14a123rd-26b6-4d40-b14e-de3223io4nio2t","minor":"62401","identifier":"nullBeaconRegion","major":"2"},"beacons":[],"eventType":"didRangeBeaconsInRegion"}
D/com.unarin.beacon(14930): [DOM] _mapDelegateCallback() found eventType didRangeBeaconsInRegion
I/ActivityManager(  898): Killing 14930:com.unarin.oss.mobile.CordovaProximityQuickstart/u0a123 (adj 9): remove task
I/WindowState(  898): WIN DEATH: Window{44421ca8 u0 com.unarin.oss.mobile.CordovaProximityQuickstart/com.unarin.oss.mobile.CordovaProximityQuickstart.MainActivity}
florentcano commented 6 years ago

Hi @petermetz this plugin can keep monitoring beacons when the android app is killed? thanks

arielfaur commented 6 years ago

I am also struggling with this, it works fine on iOS 11 even when the app is not running. But on Android it does nothing :(

mrbroong commented 6 years ago

Having same issue, it works fine on iOS when the app is killed but on Android it doesn’t detect ibeacon of the app is killed. @petermetz can you please confirm if this works when the app is killed on Android?

prakeshcdn commented 4 years ago

Hello, Beacon scanning is not working when app is killed . do you have any solution for this issue ?

giladrom commented 4 years ago

This plugin does not support background scanning on android. You need to implement a background task using altbeacon in Java.

Sent from my iPhone

On Mar 11, 2020, at 11:08 PM, prakeshcdn notifications@github.com wrote:

 Hello, Beacon scanning is not working when app is killed . do you have any solution for this issue ?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.

prakeshcdn commented 4 years ago

Hello @giladrom

How to implement altbeacon in cordova with cordova-plugin-ibeacon. do you have any example . Please help .

giladrom commented 4 years ago

The two are separate. You will need to implement the background scanning object independent of this plugin.

See https://github.com/AltBeacon/android-beacon-library-reference https://github.com/AltBeacon/android-beacon-library-reference for an example.

On Mar 12, 2020, at 12:57 AM, prakeshcdn notifications@github.com wrote:

How to implement altbeacon in cordova with cordova-plugin-ibeacon. do you have any example . Please help .

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/petermetz/cordova-plugin-ibeacon/issues/335#issuecomment-598054292, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHNMBIRJBHZX3G73MNDLONLRHCIWHANCNFSM4EICXPUA.