0

onBeacon ServiceConnect method is to detect the beacon. For lollipop version is detecting for nougat and oreo version beacon not detecting: public void onBeaconServiceConnect() {

    RangeNotifier rangeNotifier = new RangeNotifier() {
        @Override
        public void didRangeBeaconsInRegion(Collection<Beacon> beacons, org.altbeacon.beacon.Region region) {
            Log.d(TAG, "in didRangeBeaconsInRegion " + beacons.size());
            if (beacons.size() > 0) {
                Log.d(TAG, "didRangeBeaconsInRegion called with beacon count:  " + beacons.size());
                for (Iterator<Beacon> iterator = beacons.iterator();
                     iterator.hasNext(); ) {
                    Beacon beacon = iterator.next();

                    if (beaconlist.size() > 0) {
                        Log.d(TAG, "List Size :" + beaconlist.size());
                        for (int i = 0; i < beaconlist.size(); i++) {
                            Log.d("BeaconList ", beaconlist.get(i));
                        }
                    }

                    if (!beaconlist.contains(beacon.getId1().toString())) {
                        Log.d(TAG,"In get APi");
                        getApi(beacon.getId1().toString());
                        beaconlist.add(beacon.getId1().toString());
                        Log.d(TAG, "Notify in dead state");
                        Log.d("Notify in dead state", beacon.getId1().toString());
                    }
                }
            }
        }
    };
    try {
        Log.d(TAG, "I am in startRangingBeaconsInRegion");
        beaconManager.startRangingBeaconsInRegion(new Region("myRangingUniqueId", null, null, null));
        beaconManager.addRangeNotifier(rangeNotifier);
    } catch (RemoteException e) {
        e.printStackTrace();
    }
}

This is my code can any one give solution for this issue.

Arumugam
  • 3
  • 3

1 Answers1

1

Two things to check:

  1. Have you added COARSE_LOCATION permission to your AndroidManifest.xml and added code to successfully obtain that permission from the user dynamically at runtime?

  2. Do you successfully construct a BeaconManager, call bind(...) and verify you get a callback to onBeaconServiceConnect() before starting ranging? If you do not, you will get a RemoteException when you try to start ranging. It is a good idea to log this exception to LogCat with Log.e(TAG, "Not bound to beacon scanning service")

davidgyoung
  • 63,876
  • 14
  • 121
  • 204