更新时间:2022-06-24 03:09:33
问题是,当您的应用程序进入后台时, MainActivity
将调用 onPause
,并且该方法中的代码将调用 mBeaconManager.unbind(this);
方法,可以有效地停止信标的测距。
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);
到 BeaconApp
类' didDetermineStateForRegion
方法。您还需要将 didRangeBeaconsInRegion
和 showNotification
方法也移到那里。
to the BeaconApp
class' didDetermineStateForRegion
method. You'll also need to move the didRangeBeaconsInRegion
and showNotification
methods there, too.