Android iBeacon App not working in the background

前端 未结 1 671
我寻月下人不归
我寻月下人不归 2021-01-17 02:33

I have developed Android app to detect the beacon if the customer is near to 1 mt distance . I am using Android Beacon Library to develop the application.When we are in for

1条回答
  •  北海茫月
    2021-01-17 02:56

    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.

    0 讨论(0)
提交回复
热议问题