AltBeacon / android-beacon-library-reference

A reference application for the Android Beacon Library
Apache License 2.0
275 stars 187 forks source link

Activity cannot be started from background after beacon was detected #65

Open VictorCorchez opened 3 years ago

VictorCorchez commented 3 years ago

08-10 12:57:41.554 16404 16809 D MainActivity: Current region state is: INSIDE 08-10 12:57:41.554 16404 16809 D MainActivity: Got a didEnterRegion call 08-10 12:57:41.554 16404 16809 D MainActivity: Calling startActivity() 08-10 12:57:41.556 1289 3046 D OemSceneCallBlock: isCallBlockedWithUidIntent { act=android.intent.action.MAIN flg=0x18000000 cmp=/.MainActivity }, ResolveInfo{c0dfce1 /.MainActivity m=0x0}, false 08-10 12:57:41.557 1289 3046 I ActivityTaskManager: START u0 {act=android.intent.action.MAIN flg=0x18000000 cmp=/.MainActivity} from uid 10756 pid 16404

This happens while testing on Android 10 and seems this could be the explanation: https://developer.android.com/guide/components/activities/background-starts

davidgyoung commented 3 years ago

@VictorCorchez, yes, I believe your analysis of the problem is correct. It is no longer possible for apps to launch activities from the background.

While the original version of this reference app did try to launch an activity from the background, I removed that and replaced it with a notification last year in the commit below. Perhaps you are still using an old copy of the reference app? If there is something posted today that still has code to do this, please let us know.

https://github.com/AltBeacon/android-beacon-library-reference/commit/0183083517e915b345a2722dfae37267a9534fad

VictorCorchez commented 3 years ago

so is there is no other way of launching an activity from background without user interaction? I was thinking maybe this library could use the CompanionDevice approach. But I'm not sure if it works the same to be able to launch my app if it detects the beacon.

davidgyoung commented 3 years ago

As of Android 10 I do not believe this is possible anymore per the link you provided in this issue. I see nothing in Companion Device Pairing that would help here

VictorCorchez commented 3 years ago

What about this: https://developer.android.com/reference/android/Manifest.permission#REQUEST_COMPANION_RUN_IN_BACKGROUND and https://developer.android.com/reference/android/companion/CompanionDeviceManager#startObservingDevicePresence(java.lang.String) ?

Also it old example still appears here: https://altbeacon.github.io/android-beacon-library/samples-java.html