我正在试验的Android信标库,我能够使其工作与苹果兼容的信标监测和测距添加自定义解析器(请参阅这是正确的布局,以检测iBeacons与AltBeacon的Android信标库?)
现在我正在尝试使用此处显示的示例代码编写一个在后台启动的应用程序:
http://altbeacon.github.io/android-beacon-library/samples.html
这是我的代码:
public class IBeaconBootstrap extends Application implements BootstrapNotifier {
private RegionBootstrap regionBootstrap;
@Override
public void onCreate() {
super.onCreate();
Log.d("IBeaconBootstrap", "App started up");
// wake up the app when any beacon is seen (you can specify specific id
// filers in the parameters below)
Region region = new Region("MyRegion", null, null, null);
regionBootstrap = new RegionBootstrap(this, region);
}
@Override
public void didDetermineStateForRegion(int state, Region region) {
// Don't care
// MonitorNotifier.INSIDE
Log.d("Boostrap didDetermineStateForRegion", "Region " + region.toString());
}
@Override
public void didEnterRegion(Region region) {
Log.d("Boostrap didEnterRegion", "Got a didEnterRegion call");
// This call to disable will make it so the activity below only gets
// launched the first time a beacon is seen (until the next time the app
// is launched)
// if you want the Activity to launch every single time beacons come
// into view, remove this call.
regionBootstrap.disable();
Intent intent = new Intent(this, MainActivity.class);
// IMPORTANT: in the AndroidManifest.xml definition of this activity,
// you must set android:launchMode="singleInstance" or you will get two
// instances
// created when a user launches the activity manually and it gets
// launched from here.
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
this.startActivity(intent);
}
@Override
public void didExitRegion(Region region) {
Log.d("Boostrap didExitRegion", "Got a didExitRegion call");
}
}
不幸的是,它不起作用。这些函数永远不会被调用:
我预计至少“确定状态”区域被称为“创建区域引导”。
问题:
0)我错过了什么?
1)该功能是否也适用于Apple兼容的iBeacons?
先谢谢你。
更新0:
按照davidgyoung的指示,我最终让它工作,更改onCreate函数如下:
@Override
public void onCreate() {
Log.d("IBeaconBootstrap", "App started up");
// wake up the app when any beacon is seen (you can specify specific id
// filers in the parameters below)
Region region = new Region("MyRegion", null, null, null);
regionBootstrap = new RegionBootstrap(this, region);
BeaconManager.getInstanceForApplication(this).getBeaconParsers().add(new BeaconParser().setBeaconLayout("m:0-3=4c000215,i:4-19,i:20-21,i:22-23,p:24-24"));
super.onCreate();
}
我还有两个问题:
0)应用程序每3-5分钟检查一次iBeacons的存在,是否有任何方法可以静态或动态更改此间隔?
1) 显然,当检测到iBeacon正在运行时,应用程序会进入前台,但如果应用程序没有运行,则不会发生任何事情。这是预期的行为还是应用程序在未运行时应该启动?
要知道,现成的库只适用于支持开放AltBeacon标准的信标。为了将所有知识产权排除在开源库之外,这是必要的。如果您希望使库与专有信标一起工作,则必须在onCreate
方法中添加一行,以添加不同的BeaconParser实例。
BeaconManager.getInstanceForApplication().getBeaconParsers()
.add(new BeaconParser().setBeaconLayout("put-your-parser-expression-here"));
您需要将字符串“把解析器表达式放在这里”替换为一个可以检测您正在使用的专有信标的字符串。为了找到各种专有信标的解析器表达式,请尝试在Google上搜索“getBeaconParser”(包括搜索中的引号)
我想检测来电。我是用广播接收器做的,效果很好。但当我的应用程序关闭时,它会显示“应用程序已停止”(应用程序崩溃)。那么我如何启动我的应用程序来执行操作呢? 这是我的收音机:
问题内容: 我的问题很简单,我该如何识别首次申请?我认为可以通过在RMS中保存一些值并在应用启动时读取它并决定要做什么来实现。 但是没有更简单的解决方案吗? 问题答案: 据我所知,没有比这更简单的方法了,但这还是很容易的。
我正在开发一个在后台计算算法的应用程序。从应用程序启动到结束。这是一个跟踪算法(现在进一步解释算法的工作原理)。 因此,需要在应用程序的所有屏幕上计算后台任务,而不管用户在应用程序上的操作、单击、wifi通信消息(已在应用程序上完成),当算法在后台运行时,需要完成所有操作。 它是异步任务吗?如果没有,还有什么?应用程序正在运行,算法正在特定屏幕上计算,我想让它成为一个后台进程,与当前应用程序屏幕无
问题内容: 有什么方法可以知道我的应用程序的状态是后台模式还是前台模式。谢谢 问题答案: 将返回应用程序的当前状态,例如: UIApplicationStateActive UIApplicationStateInactive UIApplicationStateBackground 迅捷3+ 目标C
我有一份Java申请。 应用程序有一个决定应用程序是否在启动时启动的设置。 目前,我通过在StartUp items文件夹中放置/删除快捷方式实现了这一点。 然而,我想知道是否有更好的方法来处理这种行为。 编辑 是的,是视窗。抱歉之前没有清除。 应用程序有一个UI,用户可以在其中触发操作,并且应用程序在运行时定期在后台运行一些任务。 @Peter,如何使用应用程序中的代码更改注册表?这种方法是否与
来自Firebase网站上的文档:https://firebase.google.com/docs/cloud-messaging/downstream 当您的应用处于后台时传递的通知。在这种情况下,通知会传递到设备的系统托盘。默认情况下,用户单击通知会打开应用启动器。 当我的应用程序收到云消息并且我的应用程序在后台时,如果我需要做些什么。 是否可以在自定义BroadcastReceiver或服务