我正在我的应用程序中监视 Kontakt 信标,并且我正在使用 SpaceListener 以了解用户何时进入区域以及用户何时离开该区域。问题是我不断收到和区域进入和区域被放弃。我正在使用该库的 3.2.0 版本。信标距离我只有 1m,而且我和信标都没有移动。这是正常行为吗?
@Override
public void onCreate() {
super.onCreate();
proximityManager = new ProximityManager(this);
proximityManager.setIBeaconListener(createIBeaconListener());
proximityManager.setSpaceListener(new SpaceListener() {
@Override
public void onRegionEntered(IBeaconRegion region) {
Log.d(TAG,"onRegionEntered");
}
@Override
public void onRegionAbandoned(IBeaconRegion region) {
Log.d(TAG,"onRegionAbandoned");
}
@Override
public void onNamespaceEntered(IEddystoneNamespace namespace) {
}
@Override
public void onNamespaceAbandoned(IEddystoneNamespace namespace) {
}
});
proximityManager.configuration()
.scanMode(ScanMode.BALANCED)
.activityCheckConfiguration(ActivityCheckConfiguration.MINIMAL)
.forceScanConfiguration(ForceScanConfiguration.MINIMAL);
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
super.onStartCommand(intent, flags, startId);
proximityManager.connect(new OnServiceReadyListener() {
@Override
public void onServiceReady() {
proximityManager.startScanning();
}
});
return START_STICKY;
}
private IBeaconListener createIBeaconListener() {
return new SimpleIBeaconListener() {
private SFBeacon nearestBeacon;
@Override
public void onIBeaconDiscovered(IBeaconDevice iBeaconDevice, IBeaconRegion region) {
Log.d(TAG,"----------------------------------------------");
Log.d(TAG,"Detected: "+iBeaconDevice.getUniqueId()+" "+iBeaconDevice.getProximityUUID().toString()+" "+iBeaconDevice.getMajor()+" "+iBeaconDevice.getMinor());
}
}