【发布时间】:2016-08-09 16:04:24
【问题描述】:
我正在尝试在 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 在构建过程中生成它。如果我创建一个应用程序类并将其放在清单上,它将覆盖我的 Titanium 应用程序应用程序类和 不会运行它。
此外,在模块类“AndroidAltbeaconModuleModule”中,我尝试实现 BootstrapNotifier 接口及其方法:didDetermineStateForRegion、didEnterRegion 和 didExitRegion。
然后在onAppCreate方法上尝试实现:
Region region = new Region("My Region", Identifier.parse(
"00000000-0000-0000-0000-000000000001"), null, null);
regionBootstrap = new RegionBootstrap(this, region);
但regionBootstrap 上的this 构造函数不是静态的,并且出现错误。
其次,我尝试创建一个非静态方法并从模块中调用此代码。它成功地侦听 BootstrapNotifier 事件,但如果应用程序被杀死,则不会,仅在后台。 这是因为 regionBootstrap 不在 Application 类的 onCreate 方法中吗? 我检查了这个问题Using the AltBeacon library without extending Application 和这个Implementing BootstrapNotifier on Activity instead of Application class 以及 davidgyoung(Altbeacon 库的创建者)给出了一个很好的答案,但不可能(至少对我而言)用 Titanium 来实现。
是否只有通过此应用程序功能发现应用程序被终止的信标?我已经尝试在模块中实现一个 JobService 和一个 BroadcastReceiver 但我不是一个很好的 Java/Android 开发人员 这可能需要很多时间。 有没有人有额外的想法?请分享它=)
提前致谢!
【问题讨论】:
标签: android titanium appcelerator-titanium altbeacon