Altbeacon Android - 应用程序被杀死时的EnterRegion(非后台)

时间:2016-08-09 16:04:25

标签: android titanium appcelerator-titanium altbeacon

我正试图在Android上关闭(杀死)应用程序时听到Beacons(刷掉任务管理器)。

我正在使用Appcelerator Titanium 5+和使用模块https://github.com/dwk5123/android-altbeacon-module的信标。 该应用程序在背景上工作正常,但在关闭它时不能正常工作。 我已经尝试了在Titanium上创建应用服务的Altbeacon.setRunInService()方法,但它似乎不起作用。

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

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

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

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

其次,我尝试创建一个非静态方法并从模块中调用此代码。它成功地监听BootstrapNotifier事件,但是如果应用程序被杀死则不会,只能在后台运行。 这是因为regionBootstrap不在Application类的onCreate方法中吗? 我也检查了此问题Using the AltBeacon library without extending Application和此Implementing BootstrapNotifier on Activity instead of Application class 其中davidgyoung(Altbeacon lib的创建者)给出了一个很好的答案,但不可能(至少对我而言)用Titanium实现。

注意使用此应用程序功能杀死app的信标的唯一方法是什么?我已经尝试过在模块中实现一个JobService和一个BroadcastReceiver,但我不是一个好的Java / Android开发人员 这可能需要很长时间。 有没有人有额外的想法?请分享=)

提前致谢!

1 个答案:

答案 0 :(得分:0)

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

  1. 您是否可以创建扩展由Titanium生成的<{1}}类,然后修改AndroidManifest.xml以使用您的Application类?如果你能做到这一点,你可以在你的班级中构建Application&#39; RegionBootstrap方法,然后调用super.onCreate()来执行Titanium的任何操作。

  2. 将逻辑放入&#34; AndroidAltbeaconModuleModule&#34;的唯一方法如果该模块的代码在后台启动应用程序时立即执行(例如,在手机启动时接收到RECEIVE_BOOT_COMPLETED),则可行。此时将没有用户界面。如果它确实是如何工作的话,那么它可能是可能的,但你必须以某种方式访问​​Titanium中的Android onCreate对象,并使用它来构造一个新的本机Java类,它实现了所有的方法。 Context

  3. 总有其他方法可以完成这项工作。 BootStrapNotifier旨在使这种相对无痛。如果由于Titanium的限制你无法使用它,那么你需要从头开始构建它的一些功能,这无疑需要编写至少一个原生的RegionBootstrap

相关问题