Is background monitoring of Eddystone
beacon using altbeacon library on android platform possible? How can I achieve it?
Following is the code by which I can detect beacons with a specified UUID when the app is launched, but I want to achieve the same when the app is not running.
public class MainActivity extends ActionBarActivity implements BeaconConsumer,MonitorNotifier
{
private BeaconManager beaconManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
protected void onResume() {
super.onResume();
beaconManager = BeaconManager.getInstanceForApplication(this.getApplicationContext());
beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout("s:0-1=feaa,m:2-2=00,p:3-3:-41,i:4-13,i:14-19"));
beaconManager.bind(this);
}
@Override
public void onBeaconServiceConnect() {
Identifier myBeaconNamespaceId = Identifier.parse("0xe2bfcc3cc2370789caef");
Region region = new Region("my-beacon-region", myBeaconNamespaceId, null, null);
beaconManager.setMonitorNotifier(this);
try {
beaconManager.startMonitoringBeaconsInRegion(region);
} catch (RemoteException e) {
e.printStackTrace();
}
}
@Override
public void didEnterRegion(Region region) {
Log.d("radbeacon", "Beacon detected with namespace id " + region.getId1() +" and instance id: " + region.getId2());
}
@Override
public void didExitRegion(Region region) {
Log.d("radbeacon", "Beacon out of region with namespace id " + region.getId1() +" and instance id: " + region.getId2());
}
@Override
public void didDetermineStateForRegion(int i, Region region) {
//Ignore
}
}