本文介绍了如何在Android中检测iBeacon?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我第一次与iBeacon合作.因此,您能告诉我如何检测它(给我一些代码示例).非常感谢.对我来说很重要.

It is the first time I work with iBeacon. So can you tell me how to detect it(give me some code example). Thanks very much. It is very important to me.

推荐答案

开放源代码 Android iBeacon库将允许你这样做.

The open source Android iBeacon Library will allow you to do this.

这是一个基本的代码示例:

Here is a basic code sample:

public class MonitoringActivity extends Activity implements IBeaconConsumer {
  protected static final String TAG = "RangingActivity";
  private IBeaconManager iBeaconManager = IBeaconManager.getInstanceForApplication(this);

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_ranging);
    iBeaconManager.bind(this);
  }
  @Override
  protected void onDestroy() {
    super.onDestroy();
    iBeaconManager.unBind(this);
  }
  @Override
  public void onIBeaconServiceConnect() {
    iBeaconManager.setMonitorNotifier(new MonitorNotifier() {
    @Override
    public void didEnterRegion(Region region) {
      Log.i(TAG, "I just saw an iBeacon for the firt time!");
    }

    @Override
    public void didExitRegion(Region region) {
      Log.i(TAG, "I no longer see an iBeacon");
    }

    @Override
    public void didDetermineStateForRegion(int state, Region region) {
        Log.i(TAG, "I have just switched from seeing/not seeing iBeacons: "+state);
    }
    });

    try {
        iBeaconManager.startMonitoringBeaconsInRegion(new Region("myMonitoringUniqueId", null, null, null));
    } catch (RemoteException e) {   }
  }

}

全部披露:我是Radius Networks的首席工程师,也是该库的作者.

Full disclosure: I am Chief Engineer for Radius Networks and author of the library.

这篇关于如何在Android中检测iBeacon?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-14 00:02