我正在尝试将 Estimote SDK 添加到我的 Android 应用程序中。我已经很接近了,但是我在监视某个区域时遇到了一些麻烦。我在https://github.com/Estimote/Android-SDK关注 GitHub 上的 Estimote Android SDK 指南。
出于某种原因,onEnteredRegion 和 onExitedRegion 方法根本没有触发。我希望他们在应用程序看到 Estimote 信标时触发。谢谢!
这是我到目前为止的代码。没什么太复杂的:
public class MainActivity extends Activity {
private static final Region ALL_ESTIMOTE_BEACONS = new Region("regionId", "B9407F30-F5F8-466E-AFF9-25556B57FE6D", null, null);
BeaconManager beaconManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
beaconManager = new BeaconManager(this);
beaconManager.setBackgroundScanPeriod(TimeUnit.SECONDS.toMillis(1), 0);
beaconManager.setMonitoringListener(new MonitoringListener() {
@Override
public void onEnteredRegion(Region region, List<Beacon> beacons) {
builder.setTitle("Entered Region")
.setMessage("")
.setNeutralButton("OK", null);
AlertDialog dialog = builder.create();
dialog.show();
}
@Override
public void onExitedRegion(Region region) {
builder.setTitle("Exited Region")
.setMessage("")
.setNeutralButton("OK", null);
AlertDialog dialog = builder.create();
dialog.show();
}
});
}
protected void onStart() {
super.onStart();
try {
beaconManager.startMonitoring(ALL_ESTIMOTE_BEACONS);
}
catch (RemoteException e) {
}
}
}