I worked with the Android iBeaon library in that for background scanning I created a service and in the service I defined both monitoring and ranking. I start the service when the application shuts down and its work is for me. Create a new service like this.
public class Beaconservice extends Service implements IBeaconConsumer { private ArrayList<IBeacon> arrayL = new ArrayList<IBeacon>(); private BeaconServiceUtility beaconUtill = null; private IBeaconManager iBeaconManager = IBeaconManager.getInstanceForApplication(this); private Handler hand; private Runnable runn; private int count = 30; @Override public void onIBeaconServiceConnect() { iBeaconManager.setRangeNotifier(new RangeNotifier() { @Override public void didRangeBeaconsInRegion(Collection<IBeacon> iBeacons, Region region) { arrayL.clear(); arrayL.addAll((ArrayList<IBeacon>) iBeacons); if(count>0){ count=0; } } }); iBeaconManager.setMonitorNotifier(new MonitorNotifier() { @Override public void didEnterRegion(Region region) { Log.e("BeaconDetactorService", "didEnterRegion");
In AndroidManifest.xml
<service android:name="com.beacone.keyfinder.app.Beaconservice" > </service>
source share