Altbeacon Android - EnterRegion while app is killed (not background)
Asked Answered
N

1

0

I'm trying to listen to Beacons when the app is closed (killed) on Android (swiped off task manager).

I'm using Appcelerator Titanium 5+ and for the beacons using the module https://github.com/dwk5123/android-altbeacon-module. The app works just fine when is on background, but not when you close it. I've tried the Altbeacon.setRunInService() method creating an app service on Titanium and it doesn't seem to work.

I've also tried to modify the module to implement this http://altbeacon.github.io/android-beacon-library/background_launching.html but I'm not able to access the Application class because Titanium is generating it on the build process. If I create an Application class and put it on the manifest it will overwrite my Titanium app Application class and will not run it.

Also, in the module class "AndroidAltbeaconModuleModule" I tried to implement the BootstrapNotifier interface and its methods: didDetermineStateForRegion, didEnterRegion and didExitRegion. Then on onAppCreate method tried to implement:

Region region = new Region("My Region", Identifier.parse(
"00000000-0000-0000-0000-000000000001"), null, null);
regionBootstrap = new RegionBootstrap(this, region);

but this on regionBootstrap constructor is not static and got an error about it.

Secondly, I tried to create a non-static method and call this code from the module. It successfully listen to BootstrapNotifier events but not if the app is killed, only on background. Is this because the regionBootstrap isn't in the onCreate method of the Application class? I checked this question Using the AltBeacon library without extending Application and this Implementing BootstrapNotifier on Activity instead of Application class as well where davidgyoung (creator of the Altbeacon lib) gave a good answer but not possible (at least for me) to be implemented with Titanium.

Is the only way to notice a beacon with app killed with this Application functionality? I've tried a little to implement a JobService and a BroadcastReceiver in the module but I'm not such a good Java/Android developer and this could take a lot of time. Does anyone have an extra idea? Please share it =)

Thanks in advance!

Neumeyer answered 9/8, 2016 at 16:4 Comment(0)
M
0

I am not a Titanium expert, but I do have two suggestions:

  1. Could you make an Application class that extends the one generated by Titanium, and then modify your AndroidManifest.xml to use your Application class? If you can do this, you could construct the RegionBootstrap in your class' onCreate method, and then call super.onCreate() to execute whatever Titanium does.

  2. The only way putting the logic inside your "AndroidAltbeaconModuleModule" will work is if that module's code is executed immediately on launch of the app in the background (e.g. after receiving RECEIVE_BOOT_COMPLETED when the phone starts). There will be no UI at this point. If this is indeed how it works, then it may be possible, but you will have to somehow get access to an Android Context object in Titanium, and use this to construct a new native Java class that implements all the methods of BootStrapNotifier.

There are always other ways to get this done. The RegionBootstrap is designed to make this relatively painless. If you can't use it due to the constraints of Titanium, then you will need to build some of what it does from scratch, which will undoubtedly require writing at least a native BroadcastReceiver.

Middleoftheroad answered 9/8, 2016 at 21:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.