埃迪斯通灯塔使用altbeacon库Android平台后台监控 [英] Background monitoring of Eddystone beacon using altbeacon library on android platform

查看:1089
本文介绍了埃迪斯通灯塔使用altbeacon库Android平台后台监控的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

的Eddystone的后台监控灯塔使用altbeacon库Android平台可能吗?我怎样才能实现呢?

以下是code。通过它我可以检测到信标与指定的UUID时,应用程序启动,但我想实现当应用程序没有运行一样。

 公共类MainActivity扩展ActionBarActivity实现BeaconConsumer,MonitorNotifier
{

私人BeaconManager beaconManager;
@覆盖
保护无效的onCreate(包savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.activity_main);
}


@覆盖
保护无效onResume(){
    super.onResume();
    beaconManager = BeaconManager.getInstanceForApplication(this.getApplicationContext());
    。beaconManager.getBeaconParsers()增加(新BeaconParser()setBeaconLayout(S:0-1 = FEAA,M:2-2 = 00,P:3-3:-41,我:4-13,I:14 -19));
    beaconManager.bind(本);
}

@覆盖
公共无效onBeaconServiceConnect(){

    标识符myBeaconNamespaceId = Identifier.parse(0xe2bfcc3cc2370789caef);
    地区地区=新区域(我的信标区域,myBeaconNamespaceId,NULL,NULL);
    beaconManager.setMonitorNotifier(本);
    尝试 {
        beaconManager.startMonitoringBeaconsInRegion(区);
    }赶上(RemoteException的E){
        e.printStackTrace();
    }
}

@覆盖
公共无效didEnterRegion(地区区域){

        Log.d(radbeacon,信标探测与命名空间ID+ region.getId1()+和实例ID:+ region.getId2());
}

@覆盖
公共无效didExitRegion(地区区域){

    Log.d(radbeacon,烽火台用空间ID区的+ region.getId1()+和实例ID:+ region.getId2());
}

@覆盖
公共无效didDetermineStateForRegion(INT I,地区区域){
      //忽略
}


}
 

解决方案

是的,这是可以检测的Eddystone信标与的 Android的灯塔库。 您以同样的方式与AltBeacon或iBeacon这样做。细节在href="http://altbeacon.github.io/android-beacon-library/samples.html" rel="nofollow">在样品的背景部分开始应用的

编辑:作为FOF库版本2.7,埃迪斯通的帧支持硬件加速的发现增加了,这意味着在Android 5+的设备,你可以约在5秒钟内得到后台检测

其基本思想是,你需要创建一个中央的Andr​​oid 应用程序类的应用程序,并创建一个 RegionBootstrap 对象是类的的onCreate 方法。重要的是要记住,你必须注册这个应用程序类在你的清单是非常重要的。样品code上面链接向您展示了如何做到这一点。

所以,你最终会喜欢的东西如下:

 公共类MyApplication的扩展应用实现BootstrapNotifier {
    私有静态最后字符串变量=MyApplication的;
    私人RegionBootstrap regionBootstrap;
    私人BackgroundPowerSaver backgroundPowerSaver;
    私人BeaconManager mBeaconManager;

    公共无效的onCreate(){
        super.onCreate();
        mBeaconManager = org.altbeacon.beacon.BeaconManager.getInstanceForApplication(本);
        mBeaconManager.getBeaconParsers()清()。
        mBeaconManager.getBeaconParsers()。添加(新BeaconParser()。
            setBeaconLayout(BeaconParser.EDDYSTONE_UID_LAYOUT));
        标识符myBeaconNamespaceId = Identifier.parse(0xe2bfcc3cc2370789caef);
        地区地区=新区域(我的信标区域,myBeaconNamespaceId,NULL,NULL);

        regionBootstrap =新RegionBootstrap(这一点,区);

        backgroundPowerSaver =新BackgroundPowerSaver(本);
    }

    @覆盖
    公共无效didEnterRegion(地区区域){

            Log.d(radbeacon,信标探测与命名空间ID+ region.getId1()+和实例ID:+ region.getId2());
    }

    @覆盖
    公共无效didExitRegion(地区区域){

        Log.d(radbeacon,烽火台用空间ID区的+ region.getId1()+和实例ID:+ region.getId2());
    }

    @覆盖
    公共无效didDetermineStateForRegion(INT I,地区区域){
          //忽略
    }
...
}
 

Is background monitoring of Eddystone beacon using altbeacon library on android platform possible? How can I achieve it?

Following is the code by which I can detect beacons with a specified UUID when the app is launched, but I want to achieve the same when the app is not running.

public class MainActivity extends ActionBarActivity implements BeaconConsumer,MonitorNotifier
{

private BeaconManager beaconManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}


@Override
protected void onResume() {
    super.onResume();
    beaconManager = BeaconManager.getInstanceForApplication(this.getApplicationContext());
    beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout("s:0-1=feaa,m:2-2=00,p:3-3:-41,i:4-13,i:14-19"));
    beaconManager.bind(this);
}

@Override
public void onBeaconServiceConnect() {

    Identifier myBeaconNamespaceId = Identifier.parse("0xe2bfcc3cc2370789caef");
    Region region = new Region("my-beacon-region", myBeaconNamespaceId, null, null);
    beaconManager.setMonitorNotifier(this);
    try {
        beaconManager.startMonitoringBeaconsInRegion(region);
    } catch (RemoteException e) {
        e.printStackTrace();
    }
}

@Override
public void didEnterRegion(Region region) {

        Log.d("radbeacon", "Beacon detected with namespace id " + region.getId1() +" and instance id: " + region.getId2());
}

@Override
public void didExitRegion(Region region) {

    Log.d("radbeacon", "Beacon out of region with namespace id " + region.getId1() +" and instance id: " + region.getId2());
}

@Override
public void didDetermineStateForRegion(int i, Region region) {
      //Ignore
}


}

解决方案

Yes, it is possible to detect Eddystone beacons in the background with the Android Beacon Library. You do so in the same manner as with AltBeacon or iBeacon. Details are described in the Starting App in the Background section of the samples.

EDIT: As fof Library version 2.7, support for hardware accelerated discovery of Eddystone frames has been added, meaning that on Android 5+ devices you can get background detections within about 5 seconds.

The basic idea is you need to create a central android Application class for your app, and create a RegionBootstrap object in the onCreate method of that class. It is important to remember that you must register this Application class in your manifest. The sample code linked above shows you how to do this.

So you'd end up with something like below:

public class MyApplication extends Application implements BootstrapNotifier {
    private static final String TAG = "MyApplication";
    private RegionBootstrap regionBootstrap;
    private BackgroundPowerSaver backgroundPowerSaver;
    private BeaconManager mBeaconManager;

    public void onCreate() {
        super.onCreate();
        mBeaconManager = org.altbeacon.beacon.BeaconManager.getInstanceForApplication(this);
        mBeaconManager.getBeaconParsers().clear();
        mBeaconManager.getBeaconParsers().add(new BeaconParser().
            setBeaconLayout(BeaconParser.EDDYSTONE_UID_LAYOUT));
        Identifier myBeaconNamespaceId = Identifier.parse("0xe2bfcc3cc2370789caef");
        Region region = new Region("my-beacon-region", myBeaconNamespaceId, null, null);

        regionBootstrap = new RegionBootstrap(this, region);

        backgroundPowerSaver = new BackgroundPowerSaver(this);
    }

    @Override
    public void didEnterRegion(Region region) {

            Log.d("radbeacon", "Beacon detected with namespace id " + region.getId1() +" and instance id: " + region.getId2());
    }

    @Override
    public void didExitRegion(Region region) {

        Log.d("radbeacon", "Beacon out of region with namespace id " + region.getId1() +" and instance id: " + region.getId2());
    }

    @Override
    public void didDetermineStateForRegion(int i, Region region) {
          //Ignore
    }
...
}

这篇关于埃迪斯通灯塔使用altbeacon库Android平台后台监控的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆