问题描述
我正在尝试在Android上关闭(杀掉任务管理器)的应用程序(杀死)时收听信标.
我正在使用Appcelerator Titanium 5+,并使用模块 https://github.com/dwk5123/android-altbeacon-module . 该应用程序在背景上时工作正常,但在您关闭它时没有. 我已经尝试了altbeacon.setruninservice()方法在钛上创建应用程序服务,似乎没有工作.
我还尝试修改模块来实现这个 http://altbeacon.github.io/android-beacon-library/background_launching.html 但我无法访问 应用程序类因为钛正在构建过程中生成它.如果我创建一个应用程序类并将其放在清单上,它将覆盖我的Titanium App应用程序类和 不会运行它.
此外,在模块类中,"androidaltbeaconmodulemodulemodule"我试图实现引导程序接口及其方法:didDetermineStateForRegion,didEnterRegion和didExitRegion. 然后在onAppCreate方法上试图实现:Region region = new Region("My Region", Identifier.parse( "00000000-0000-0000-0000-000000000001"), null, null); regionBootstrap = new RegionBootstrap(this, region);
但this在regionBootstrap构造函数上不是静态的,并且有一个错误.
其次,我尝试创建一个非静态方法并从模块调用此代码.它成功地侦听了引导程序事件,但如果应用程序没有杀死,那么它就不是在背景上杀死. 这是因为区域BootStrap不是应用程序类的oncreate方法? 我选中了这个问题不扩展应用程序,这个<一个href ="https://stackoverflow.com/questions/34824283/implementing-bootstrapnotifier-on-activity-instead-of-application-class">在活动上实现BootstrapNotifier而不是应用程序类 其中Davidgyoung(AltBeacon Lib的创建者)给出了一个很好的答案,但不可能(至少对我)进行钛合金.
是注意使用此应用程序功能杀死的应用程序的唯一方法?我已经尝试过一些在模块中实现jobservice和broadcasteceiver,但我不是一个很好的java/android开发人员 这可能需要很多时间. 有没有人有额外的想法?请分享它=)
提前感谢!
推荐答案
我不是钛专家,但我确实有两个建议:
-
可以使扩展 indanium生成的Application类,然后修改您的androidmanifest.xml以使用您的应用程序类?如果可以执行此操作,则可以在类中的"onCreate方法"中构建RegionBootstrap,然后调用super.oncreate()来执行任何钛.
-
将逻辑放入"androidaltbeaconmodulemodulemodule"中的唯一方法是如果在启动背景中的应用程序时立即执行该模块的代码(例如,在手机启动时收到Receive_Boot_Completed).此时,没有UI.如果这确实是它的工作原理,那么它可能是可能的,但是您必须以某种方式访问钛中的Android Context对象,并使用它来构造一个实现
.
有其他方法可以完成这一点. RegionBootstrap旨在使这相对无痛.如果您不能由于钛的约束而使用它,那么您需要构建它从头开始的一些,这无疑需要至少写入本机BroadcastReceiver.
问题描述
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!
推荐答案
I am not a Titanium expert, but I do have two suggestions:
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.
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.