Android iBeacon App not working in the background

我们两清 提交于 2019-12-01 14:45:57

The problem is that when your app goes to the background, the MainActivity will call onPause, and the code inside that method calls the mBeaconManager.unbind(this); method, which effectively stops beacon ranging.

If you want ranging to continue in the background, the easiest thing to do is move the following two lines:

mBeaconManager.startRangingBeaconsInRegion(new Region("treewalker", null, null, null));
mBeaconManager.addRangeNotifier(this);

to the BeaconApp class' didDetermineStateForRegion method. You'll also need to move the didRangeBeaconsInRegion and showNotification methods there, too.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!