Android 当我的应用程序未运行时,我可以监听Eddystone信标吗?
他们将在Google Play服务中为android提供支持。我们是否可以注册eddystone信标,并让我们的应用程序在应用程序未运行的情况下收到意向书?是的,可以使用完全支持的来完成此操作 后台启动应用程序的机制在Eddystone上的工作方式与库支持的其他类型信标的工作方式相同。在自定义Android 当我的应用程序未运行时,我可以监听Eddystone信标吗?,android,google-play-services,eddystone,Android,Google Play Services,Eddystone,他们将在Google Play服务中为android提供支持。我们是否可以注册eddystone信标,并让我们的应用程序在应用程序未运行的情况下收到意向书?是的,可以使用完全支持的来完成此操作 后台启动应用程序的机制在Eddystone上的工作方式与库支持的其他类型信标的工作方式相同。在自定义应用程序类中使用区域引导对象。您可以阅读有关如何工作的详细信息 与Eddystone的唯一区别在于,您必须设置一个解码Eddystone UID帧的BeaconParser,然后设置一个与Eddystone
应用程序
类中使用区域引导
对象。您可以阅读有关如何工作的详细信息
与Eddystone的唯一区别在于,您必须设置一个解码Eddystone UID帧的BeaconParser
,然后设置一个与Eddystone命名空间id匹配的区域
:
public class MyApplicationName extends Application implements BootstrapNotifier {
private static final String TAG = ".MyApplicationName";
private RegionBootstrap regionBootstrap;
@Override
public void onCreate() {
super.onCreate();
Log.d(TAG, "App started up");
BeaconManager beaconManager = BeaconManager.getInstanceForApplication(this);
// Detect the main identifier (UID) frame:
beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout("s:0-1=feaa,m:2-2=00,p:3-3:-41,i:4-13,i:14-19"));
// wake up the app when a beacon matching myEddystoneNamespaceId is seen
myEddystoneNamespaceId = Identifier.parse("0x2f234454f4911ba9ffa6");
Region region = new Region("com.example.myapp.boostrapRegion", myEddystoneNamespaceId, null, null);
regionBootstrap = new RegionBootstrap(this, region);
}
@Override
public void didDetermineStateForRegion(int arg0, Region arg1) {
// Don't care
}
@Override
public void didEnterRegion(Region arg0) {
Log.d(TAG, "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 arg0) {
// Don't care
}
}
自Google play services v8.4 SDK(2015年12月)发布以来,这一点已经成为可能 有关更多信息,请参阅以下链接:
好的,这是非常痛苦的,但我最终还是设法使用了
Nearby.Messages.subscribe(googleApiClient, new MessageListener() {
@Override
public void onFound(Message message) {
Log.i(TAG, "Found : " + message);
}
@Override
public void onLost(Message message) {
Log.i(TAG, "Lost : " + message);
}
}, new SubscribeOptions.Builder()
.setStrategy(Strategy.BLE_ONLY)
.build());
听起来这仍然需要应用程序运行——也就是说,仍然有它的进程。如果用户在哪里强制停止应用程序,它不会收到回调,因为应用程序将不会运行。是的,从技术上讲,该进程是在后台运行的,至少是为了寻找信标。但是,在用户界面显示之前,它不会显示在最近的应用程序列表(任务切换程序)中。如果用户从最近的任务列表中删除应用程序,Android Beacon Library将使用警报在5分钟内重新启动自身,以便在后台查找信标。@DavidYoung为什么不为其使用IntentService(就像处理GCM消息一样)?IntentService是从外部或系统服务(如GCM)获取消息的好方法。使用Android Beacon Library时,信标扫描服务与您的应用程序捆绑在一起,并在后台作为内部服务运行。必须仅在
应用程序
类上实现BootstrapNotifier
,如果在活动
上实现了'BootstrapNotifier',它的工作方式会不会相同?很难说附近更新的API和任何文档目前都不可用。我希望他们能实现这一点,但这只是猜测。