【问题标题】:Altbeacon Android - EnterRegion while app is killed (not background)Altbeacon Android - 应用程序被杀死时进入区域(不是后台)
【发布时间】: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


    【解决方案1】:

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

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

    2. 将逻辑放入“AndroidAltbeaconModuleModule”的唯一方法是,如果该模块的代码在后台启动应用程序时立即执行(例如,在手机启动时收到 RECEIVE_BOOT_COMPLETED 之后)。此时将没有 UI。如果这确实是它的工作原理,那么它可能是可能的,但是您必须以某种方式访问​​ Titanium 中的 Android Context 对象,并使用它来构造一个新的本机 Java 类,该类实现了 @987654325 的所有方法@。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-08
      • 2021-01-19
      相关资源
      最近更新 更多