Ranging in Android

Hello…
I was not able to find anything related to what I have described below. Hence created this post.

I have build a service in Android which detects beacons when they are in range. onEnteredRegion provides list of all beacons that are detected. However I always get only one beacon even if there are multiple which are kept one next to other.

Ideally it should be fine if onEnteredRegion detects the other beacons one by one as well. But it never returns them unless I move away from the region and walks back in. And strangely there is high possibility that the beacon detected this time might be same as the previous one but again its only one beacon detected.

In summary, onEnteredRegion return only one beacon in list even if there are multiple in the specific region.

Here is the service code I wrote for reference.

public class BeaconsMonitoringService  extends Service {
private final Region ALL_ESTIMOTE_BEACONS = new Region("rid", null, null, null);
private final String TAG = "BeaconsMonitorService";
private BeaconManager beaconManager;

BeaconManager.MonitoringListener beaconMonitoringListener = new BeaconManager.MonitoringListener() {
    @Override public void onEnteredRegion(Region region, List<Beacon> beacons) {
        Log.d(TAG, "Beacon region entered!!");
        if(Connectivity.IsNetworkAvailable(null, BeaconsMonitoringService.this.getApplicationContext(), false)) {
            int[] majors = new int[beacons.size()];
            int[] minors = new int[beacons.size()];
           
            for (int i = 0; i < beacons.size(); i++) {
                majors[i] = beacons.get(i).getMajor();
                minors[i] = beacons.get(i).getMinor();

                Log.d(TAG, "Beacon found : Major=" + majors[i] + ", Minor=" + minors[i]);
            }

        }
    }

    @Override public void onExitedRegion(Region region) {
        Log.d(TAG, "Beacon region exit!!" );
    }
};

@Override
public IBinder onBind(Intent intent) {
    // We don't provide binding, so return null
    return null;
}

@Override
public void onCreate() {
    Log.d(TAG, "Beacons monitoring service created");
}

@Override
public void onDestroy() {
    Log.d(TAG, "Beacons monitoring service stopped!!");
    beaconManager.disconnect();
    beaconManager = null;
    super.onDestroy();
}

@Override
public int onStartCommand(final Intent intent, int flags, final int startId) {
    final int _flags = flags;
    beaconManager = new BeaconManager(this.getApplicationContext());
    beaconManager.connect(new BeaconManager.ServiceReadyCallback() {
        @Override public void onServiceReady() {
            try {
                Log.d(TAG, "serviceReady");
                beaconManager.startMonitoring(ALL_ESTIMOTE_BEACONS);
                Log.d(TAG, "serviceReady complete");
            } catch (Exception e) {
                Log.e(TAG, "Cannot start ranging", e);
 //Restart the service in case of error thrown
                onStartCommand(intent, _flags, startId);
            }
        }
    });

    beaconManager.setMonitoringListener(beaconMonitoringListener);

    Log.d(TAG, "Beacons monitoring service started!!");

    // If we get killed, after returning from here, restart
    return START_STICKY;
}
}

It looks like you need ranging instead of monitoring.

Have you went through our Android tutorial? It explains the difference between the two, and also how to use them:

http://developer.estimote.com/android/tutorial/part-1-setting-up/

We have implemented ranging for the users who are active in our app. However when app is not active we use a service that detects the beacon using monitoring.

The issue is it detects only one beacon out of the pool when someone enters into the region where as the call back listener supports the list of beacons. And same is true when we do ranging when user is active. The call back listener always give one beacon at a time even though both listeners for ranging and monitoring returns a list of beacons.

I looked at the documents and it also talks about using Monitoring listeners for background notification and tasks. Which is what I am doing.

The issue is it always gives only one beacon even if multiple are kept in a region.