How to reduce the range detection interval in beacon for Android

人走茶凉 提交于 2019-12-24 19:22:32

问题


I have using Android Beacon Library for one of my beacon solution . I can see that if I enter the beacon range ..it calls the "didEnterRegion" function but it never enter the "didExitRegion" when I go off the beacon region . I am taking the above code which I used in here Android iBeacon App not working in the background . In addition to that is there any way I can reduce the range detection because I keep on getting that very frequently because logically I want to record the data and send the notification once if customer enter beacons in 1 mt range.


回答1:


In the code shown in the other question, the didEnter Region method disables monitoring with regionBootstrap.disable() If you don't want it disabled, remove that code.

@Override
public void didEnterRegion(Region arg0) {
    Log.d(TAG, "Got a didEnterRegion call");
    // This call to disable will make it so the activity below only gets launched the first time a beacon is seen (until the next time the app is launched)
    // if you want the Activity to launch every single time beacons come into view, remove this call.
    regionBootstrap.disable();
    Intent intent = new Intent(this, MainActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    // Important:  make sure to add android:launchMode="singleInstance" in the manifest
    // to keep multiple copies of this activity from getting created if the user has
    // already manually launched the app.
    this.startActivity(intent);


}

If you don't want to send a notification until a user is < 1m, you must use the didRangeBeaconsInRegion callback, and then only fire the notification if beacon.getDistance < 1.0.



来源:https://stackoverflow.com/questions/45026653/how-to-reduce-the-range-detection-interval-in-beacon-for-android

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