-->

How to increase the delay in the data of the regio

2019-08-22 05:44发布

问题:

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