Does Android Beacon Library support background scanning?

I am using Android Beacon Library to scan BLE with example . It works great in the foreground for monitoring and ranking. However, for the background, it works only for cases when you press "Home" in the application and the screen is off. This does not work when I kill the application from the task switcher. In this example, I cannot find anything similar to Service to make everything work in the background.

Questions:

  • Does Android Beacon Library support background scanning if the application is killed in the task switcher?
  • If so, how to do it? Any example?
+5
source share
3 answers

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"); // logStatus("I just saw an iBeacon for the first time!"); } @Override public void didExitRegion(Region region) { Log.e("BeaconDetactorService", "didExitRegion"); // logStatus("I no longer see an iBeacon"); } @Override public void didDetermineStateForRegion(int state, Region region) { Log.e("BeaconDetactorService", "didDetermineStateForRegion"); // logStatus("I have just switched from seeing/not seeing iBeacons: " + state); } }); try { iBeaconManager.startRangingBeaconsInRegion(new Region("myRangingUniqueId", null, null, null)); } catch (RemoteException e) { e.printStackTrace(); } try { iBeaconManager.startMonitoringBeaconsInRegion(new Region("myMonitoringUniqueId", null, null, null)); } catch (RemoteException e) { e.printStackTrace(); } } @Override public IBinder onBind(Intent arg0) { return null; } @Override public void onCreate() { beaconUtill = new BeaconServiceUtility(this); Log.e("UUID","start service"); hand = new Handler(); runn = new Runnable() { @Override public void run() { count ++; hand.postDelayed(runn, 1000); } }; hand.post(runn); super.onCreate(); } @Override @Deprecated public void onStart(Intent intent, int startId) { beaconUtill.onStart(iBeaconManager, this); beaconUtill = new BeaconServiceUtility(this); super.onStart(intent, startId); } @Override public void onDestroy() { beaconUtill.onStop(iBeaconManager, this); super.onDestroy(); } } 

In AndroidManifest.xml

  <service android:name="com.beacone.keyfinder.app.Beaconservice" > </service> 
+3
source

Yes, Android Beacon Library will continue to detect beacons after the application is killed , but it may take time to resume scanning. See here for more details: http://altbeacon.imtqy.com/android-beacon-library/resume-after-terminate.html

The library uses AlarmManager to do this, and scanning can take up to five minutes.

The link you are linking to actually has an example of how to set it using the RegionBootstrap class. A more descriptive example is given in the code examples in the section “Launching an Application in the Background Section” here: http://altbeacon.imtqy.com/android-beacon-library/samples.html

+2
source
  • No, not another application. Killing a task with the Task Switcher means killing the process of this application, and since your background scan depends on the service, this service is also killed because the services do not start their own process.

  • Perhaps you have an AlarmManager that periodically checks to see if your service is running and starts it automatically if it is not, but I would suggest that it will hit the battery badly if you set the interval too low.

-1
source

Source: https://habr.com/ru/post/1235162/


All Articles