I am working on a bluetooth application using the AltBeacon library. It seems that only in the case of BeaconManager allowed for each application. The problem I encountered is this: I want to constantly work in the background, which constantly performs bluetooth setup and sends notifications. If I open my application (bring it to the fore), I was a service to pause. Then the front end will do the ranking and display the content on the screen.
The problem is that the beacon manager (from BeaconManager beaconManager = BeaconManager.getInstanceForApplication(this); ) in activity and maintenance is the same instance. Therefore, when the activity is closed, it calls beaconManager.unbind(this); , and the range alert in the service no longer works.
Can I get two separate copies of the lighthouse manager? If not, how can I work in continuous operation and activity?
Rangingctivity
@Override protected void onCreate(Bundle savedInstanceState) { ... regionEstimote = new Region("estimote", null, null, null); beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24")); beaconManager.bind(this); } @Override protected void onDestroy() { super.onDestroy(); notificationManager.cancel(NOTIFICATION_ID);
BeaconService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { if(beaconHistory == null) beaconHistory = new HashMap<Integer, Date>(); mBeaconManager = BeaconManager.getInstanceForApplication(this); mBeaconManager.getBeaconParsers().add(new BeaconParser(). setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24")); return START_STICKY; } @Override public void onDestroy() { super.onDestroy(); beaconHistory = null; mBeaconManager.unbind(this); } @Override public void onBeaconServiceConnect() { mBeaconManager.setRangeNotifier(new RangeNotifier() { @Override public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) { if(ActivityBase.isActivityVisible()) {
java android bluetooth ibeacon altbeacon
mashrur
source share