如何在Android中检测iBeacon?
这是我第一次与iBeacon合作。所以,你能告诉我如何检测它(给我一些代码示例)。非常感谢。这对我来说非常重要。开源将允许您这样做 下面是一个基本代码示例:如何在Android中检测iBeacon?,android,detect,ibeacon-android,Android,Detect,Ibeacon Android,这是我第一次与iBeacon合作。所以,你能告诉我如何检测它(给我一些代码示例)。非常感谢。这对我来说非常重要。开源将允许您这样做 下面是一个基本代码示例: public class MonitoringActivity extends Activity implements IBeaconConsumer { protected static final String TAG = "RangingActivity"; private IBeaconManager iBeaconMana
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网络的总工程师,也是该库的作者。开源将允许您这样做
下面是一个基本代码示例:
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网络的总工程师,也是该图书馆的作者。Hi@DavidYoung我写了一个类,不以扩展活动为例。但它不能在BeaConserviceConnect()上运行。你能告诉我原因吗。我重写了一些ibeaconsumer的方法:Hi@davidgyoung你能告诉我如何在没有活动的情况下编写实现ibeaconsumer的类吗?非常感谢。这是我的密码。我不知道为什么onIBeaconServiceConnect()不运行。谢谢你,谢谢你。非常感谢您共享的代码,我没有看到任何对iBeaconManager.bind(…)的调用,这是获得对onIBeaconServiceConnect()的回调所必需的。如果您需要更多帮助,请发布一个新问题,其中包含您的内联代码,这样其他人也可以看到它,并能够提供他们的答案。谢谢。我克服了这个问题。谢谢你的帮助!您好@davidgyoung我写了一个类,并没有像您的例子那样扩展活动。但它不能在BeaConserviceConnect()上运行。你能告诉我原因吗。我重写了一些ibeaconsumer的方法:Hi@davidgyoung你能告诉我如何在没有活动的情况下编写实现ibeaconsumer的类吗?非常感谢。这是我的密码。我不知道为什么onIBeaconServiceConnect()不运行。谢谢你,谢谢你。非常感谢您共享的代码,我没有看到任何对iBeaconManager.bind(…)的调用,这是获得对onIBeaconServiceConnect()的回调所必需的。如果您需要更多帮助,请发布一个新问题,其中包含您的内联代码,这样其他人也可以看到它,并能够提供他们的答案。谢谢。我克服了这个问题。谢谢你的帮助!