-1
public void onBeaconServiceConnect() {
    beaconManager.addMonitorNotifier(new MonitorNotifier() {
        @Override
        public void didEnterRegion(Region region) {
            try {
                beaconManager.startRangingBeaconsInRegion(region);
            } catch (RemoteException e) {

            }
        }

        @Override
        public void didExitRegion(Region region) {
            try {
                int k = 0;
                beaconManager.stopRangingBeaconsInRegion(region);
            } catch (RemoteException e) {
                int i = 0;
            }
        }

        @Override
        public void didDetermineStateForRegion(int i, Region region) {
            if (beaconManager.getRangedRegions().contains(region) == false) {
                try {
                    beaconManager.startRangingBeaconsInRegion(region);
                } catch (RemoteException e) {

                }
            }
        }
    });

    beaconManager.addRangeNotifier(new RangeNotifier() {
        @Override
        public void didRangeBeaconsInRegion(Collection<Beacon> collection, Region region) {
            for (Beacon beacon: collection) {
                int j = 0;
            }
        }
    });

    try {
        Identifier id = Identifier.parse("8492E75F-4FD6-469D-B132-043FE94921D8");
        beaconManager.startMonitoringBeaconsInRegion(new Region("8492E75F-4FD6-469D-B132-043FE94921D8", null, null, null));
    } catch (RemoteException e) {
        int i = 0;
    }
}

This is my code, everything looks fine until i get to didRangeBeaconsInRegion, beacons is always empty.

My log is full of this two lines: D/BluetoothAdapter: scan not started yet D/BluetoothAdapter: stopLeScan()

  • 1
    Make sure bluetooth is enabled and for marshmallow and later devices make sure location is enabled to get scan ble devices.. – Lalit Jadav May 30 '17 at 05:27

1 Answers1

0

Make sure you have enabled these permissions :

<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>

and If your app targets Android 5.0 (API level 21) or higher, you must declare that your app uses the android.hardware.location.network or android.hardware.location.gps

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

For more information please visit developer site