0

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);


            }


        }
    }
}
ssnegi
  • 183
  • 1
  • 1
  • 15

1 Answers1

1

There are two methods which can help you

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

Check official javadocs for details

  • Thanks for your quick response. Is there a way I can send the notification only once if the customer already passed through that region ? – ssnegi Jul 17 '17 at 12:45
  • You can use `mBeaconManager.stopRangingBeaconsInRegion(YOUR_REGION);` for that – Konstantin Kiriushyn Jul 17 '17 at 14:20
  • Note that if you change the scan periods after you have already started scanning, you will need to call `beaconManager.updateScanPeriods();` to make the changes take effect – davidgyoung Jul 17 '17 at 16:53