Altbeacon Android-应用程序被杀死时EnterEnterion(不是背景) [英] Altbeacon Android - EnterRegion while app is killed (not background)

查看:103
本文介绍了Altbeacon Android-应用程序被杀死时EnterEnterion(不是背景)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Android(关闭任务管理器)上关闭(杀死)该应用程序时收听信标.

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

我正在使用Appcelerator Titanium 5+,并且使用模块 https://github.com/dwk5123/android-altbeacon-module . 该应用程序在后台运行时效果很好,但在关闭时却无法正常运行. 我已经尝试过Altbeacon.setRunInService()方法在Titanium上创建应用程序服务,但它似乎不起作用.

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.

我还尝试修改模块以实现此 http://altbeacon.github.io/android-beacon-library/background_launching.html ,但我无法访问 应用程序类,因为Titanium是在构建过程中生成的.如果我创建一个Application类并将其放在清单上,它将覆盖我的Titanium应用程序Application类,并且 不会运行它.

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.

此外,在模块类"AndroidAltbeaconModuleModule"中,我尝试实现BootstrapNotifier接口及其方法:didDetermineStateForRegiondidEnterRegiondidExitRegion. 然后在onAppCreate方法上尝试实现:

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);

但是regionBootstrap构造函数上的this不是静态的,并且出现了错误.

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

第二,我尝试创建一个非静态方法并从模块中调用此代码.它成功侦听BootstrapNotifier事件,但仅在后台才能侦听该应用程序被杀死的事件. 这是因为regionBootstrap不在Application类的onCreate方法中吗? 我使用了AltBeacon库而不扩展应用程序,并且此<同样在href ="https://stackoverflow.com/questions/34824283/implementing-bootstrapnotifier-on-activity-instead-of-application-class">对Activity而不是Application class实施BootstrapNotifier davidgyoung(Altbeacon库的创建者)给出了一个很好的答案,但(至少对我来说)不可能用Titanium实现.

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.

是唯一注意到带有此应用程序功能的应用程序被杀死的信标的方法吗?我已经尝试了一些在模块中实现JobService和BroadcastReceiver的方法,但是我不是一个很好的Java/Android开发人员 这可能会花费很多时间. 有人有其他想法吗?请分享=)

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 =)

提前谢谢!

推荐答案

我不是Titanium专家,但是我有两个建议:

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

  1. 能否创建一个扩展 Titanium生成的那个Application类,然后修改您的AndroidManifest.xml以使用您的Application类?如果可以这样做,则可以在类的onCreate方法中构造RegionBootstrap,然后调用super.onCreate()来执行Titanium所做的任何事情.

  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.

将逻辑放入"AndroidAltbeaconModuleModule"中的唯一方法是,如果该模块的代码在后台启动应用后立即执行(例如,在手机启动时收到RECEIVE_BOOT_COMPLETED之后).此时将没有UI.如果确实如此,则有可能,但是您将不得不以某种方式访问​​Titanium中的Android Context对象,并使用它来构造一个新的本机Java类,该类实现.

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.

总是有其他方法可以完成此任务. RegionBootstrap旨在使此操作相对轻松.如果由于Titanium的限制而无法使用它,那么您将需要从头开始构建它的某些功能,这无疑将需要至少编写一个本机的BroadcastReceiver.

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.

这篇关于Altbeacon Android-应用程序被杀死时EnterEnterion(不是背景)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆