How to increase the delay in the data of the region notifier?

落花浮王杯 提交于 2019-12-11 14:40:14

问题


I have using Android Beacon Library for one of my beacon solution .Is there a way put a delay in data produced by the range notifier because it is giving data very frequently . Below is the code which I am referring to. To see complete code you can go to this thread "Android iBeacon App not working in the background"

@Override
public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) {

    if(beacons.size() > 0) {
        for (Beacon beacon : beacons) {
            if (beacon.getDistance() < 1.0) {
                Log.d(TAG, "I see a beacon transmitting a : " +
                        " approximately " + beacon.getDistance() + " meters away.");

                Log.d(TAG, "BEACON DATA : " +beacon.getBluetoothAddress()+":"+beacon.getBluetoothName()+":"+beacon.getId1());

                showNotification("Treewalker","You are near beacon range");
                Intent intent = new Intent(this,MainActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                this.startActivity(intent);


            }


        }
    }
}

回答1:


There are two methods which can help you

mBeaconManager.setBackgroundBetweenScanPeriod(10000);
mBeaconManager.setForegroundBetweenScanPeriod(10000);

Check official javadocs for details



来源:https://stackoverflow.com/questions/45142727/how-to-increase-the-delay-in-the-data-of-the-region-notifier

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