java notifier_循环中的BootstrapNotifier回调

在iOS应用中,遇到信标检测异常,表现为BootstrapNotifier回调无规律地循环触发,导致无法正常启动信标扫描。问题发生在应用启动和后台运行时。尽管尝试在不同回调中启动扫描,但循环依然存在,且扫描延迟一分钟左右才开始。代码显示已设置了iBeacon布局,并实现了相关回调,但问题依旧。可能的原因包括扫描参数设置、系统权限、硬件干扰等,需要进一步排查配置和实现细节。
摘要由CSDN通过智能技术生成

我的信标检测有问题 .

有时应用程序循环遍历BootstrapNotifier回调(didDetermineStateForRegion(int arg0,Region arg1),didEnterRegion(Region arg0)和didExitRegion(Region arg0)) .

有时会在我启动应用程序时发生,其他时候是应用程序处于后台时...我没有找到任何模式,因此我不知道问题出在哪里 .

循环就像这样(只有一块日志):

D/MyApplication: Got a didDetermineStateForRegion call: 2f234454-cf6d-4a0f-adf2-f4911ba9ffa6

D/MyApplication: Got a didEnterRegion call: 2f234454-cf6d-4a0f-adf2-f4911ba9ffa6

D/MyApplication: Got a didDetermineStateForRegion call: 2f234454-cf6d-4a0f-adf2-f4911ba9ffa6

D/MyApplication: Got a didExitRegion call: null

D/MyApplication: Got a didDetermineStateForRegion call: 2f234454-cf6d-4a0f-adf2-f4911ba9ffa6

D/MyApplication: Got a didEnterRegion call: 2f234454-cf6d-4a0f-adf2-f4911ba9ffa6

D/MyApplication: Got a didDetermineStateForRegion call: 2f234454-cf6d-4a0f-adf2-f4911ba9ffa6

D/MyApplication: Got a didExitRegion call: null

D/MyApplication: Got a didDetermineStateForRegion call: 2f234454-cf6d-4a0f-adf2-f4911ba9ffa6

D/MyApplication: Got a didEnterRegion call: 2f234454-cf6d-4a0f-adf2-f4911ba9ffa6

D/MyApplication: Got a didDetermineStateForRegion call: 2f234454-cf6d-4a0f-adf2-f4911ba9ffa6

D/MyApplication: Got a didExitRegion call: null

D/MyApplication: Got a didDetermineStateForRegion call: 2f234454-cf6d-4a0f-adf2-f4911ba9ffa6

D/MyApplication: Got a didEnterRegion call: 2f234454-cf6d-4a0f-adf2-f4911ba9ffa6

D/MyApplication: Got a didDetermineStateForRegion call: 2f234454-cf6d-4a0f-adf2-f4911ba9ffa6

D/MyApplication: Got a didExitRegion call: null

D/MyApplication: Got a didDetermineStateForRegion call: 2f234454-cf6d-4a0f-adf2-f4911ba9ffa6

D/MyApplication: Got a didEnterRegion call: 2f234454-cf6d-4a0f-adf2-f4911ba9ffa6

D/MyApplication: Got a didDetermineStateForRegion call: 2f234454-cf6d-4a0f-adf2-f4911ba9ffa6

D/MyApplication: Got a didExitRegion call: null

D/MyApplication: Got a didDetermineStateForRegion call: 2f234454-cf6d-4a0f-adf2-f4911ba9ffa6

D/MyApplication: Got a didEnterRegion call: 2f234454-cf6d-4a0f-adf2-f4911ba9ffa6

为什么会这样?该应用程序检测到该区域,但不会立即启动信标扫描 . 在这个循环或多或少一分钟之后,扫描通常开始(但不总是) .

更新 - - - - - -

我的代码:

public class BeaconApplication extends Application implements BootstrapNotifier, BeaconConsumer {

private String TAG = "MyApplication";

private BeaconManager beaconManager;

private Region region;

@Override

public void onCreate() {

super.onCreate();

startBeaconScan();

}

public void startBeaconScan() {

Log.d(TAG, "App started up");

beaconManager = BeaconManager.getInstanceForApplication(this);

beaconManager.getBeaconParsers().add(new BeaconParser().

setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25")); //iBeacon layout

beaconManager.setRegionStatePeristenceEnabled(false);

beaconManager.bind(this);

region = new Region("myMonitoringUniqueId", Identifier.parse("2f234454-cf6d-4a0f-adf2-f4911ba9ffa6"), null, null);

new RegionBootstrap(this, region);

}

@Override

public void didDetermineStateForRegion(int arg0, Region arg1) {

beaconManager.addRangeNotifier(new RangeNotifier() {

@Override

public void didRangeBeaconsInRegion(Collection beacons, Region region) {

//CODE FOR BEACON DETECTION

}

});

try {

beaconManager.startRangingBeaconsInRegion(region);

} catch (RemoteException e) {

e.printStackTrace();

}

Log.d(TAG, "Got a didDetermineStateForRegion call: " + arg1.getId1());

}

@Override

public void didEnterRegion(Region arg0) {

Log.d(TAG, "Got a didEnterRegion call: " + arg0.getId1());

}

@Override

public void didExitRegion(Region arg0) {

Log.d(TAG, "Got a didExitRegion call: " + arg0.getBluetoothAddress());

}

@Override

public void onBeaconServiceConnect() {

try {

beaconManager.setBackgroundBetweenScanPeriod(500);

beaconManager.setBackgroundScanPeriod(500);

beaconManager.setForegroundBetweenScanPeriod(500);

beaconManager.setForegroundScanPeriod(500);

beaconManager.updateScanPeriods();

} catch (RemoteException e) {

e.printStackTrace();

}

}

}

我试过“beaconManager.startRangingBeaconsInRegion(region);”在“onBeaconServiceConnect()”回调中,但似乎它没有产生任何差异 .

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值