java - Android AltBeacon Background Service Ranging -


I am working on the Bluetooth app using the AltBeacon library. It seems that only the application for BeaconManager is allowed. The problem I am facing is this: I want an ongoing moving background service which continuously sends notifications to Bluetooth. If I open my app (to bring it to the foreground) I wanted to stop the service, the foreground activity would again show the contents on the screen.

The problem is that Beacon Manager (from Beacon Manager Beacon Manager = Beacon Manager .get InstanceFor Application (this); ) is the same example in activity and service. So when the activity stops, beacon manager. Unbund (it); and the range notifier in the service no longer fires.

Can the two different examples beacon manager? If not, how can I continue in a continuous service and an activity?

color activity

  @Override Creating a secure over zero (bundle saved instenstate) {... regionEstimote = new area ("estimate", empty, null, empty ); Beacon Manager.GetbackPaper () Add (New Beaconers (.) Setbackon Layout ("m: 2-3 = 0215, i: 4-19, i: 20-21, i: 22-23, p: 24-24")); BeaconManager.bind (this); } @ Overhaired Protected Zero Destroy () {Super. Onesteroy (); NotificationManager.cancel (NOTIFICATION_ID); //beaconManager.unbind(this); } @ Override Baconseva Connect to Public Zero () {Beacon Manager. Satranzenotifier (New Renegoteifier () {....}); {Try BeaconManager.startRangingBeaconsInRegion (regionEstimote); } Hold (RemoteException E) {Log. A (tag, "color activation", e); }}  

BeaconService.java

  @Override public int onStartCommand (intended intent, int flags, int startId) {if (beaconHistory == empty) BeaconHistory = new hashmap & lt; Integer, date & gt; (); MBeaconManager = BeaconManager.stustansfreation (this); MBeaconManager.getBeaconParsers (). Add (New Beaconers (). SetBeaconLayout ("m: 2-3 = 0215, i: 4-19, i: 20-21, i: 22-23, p: 24-24")); Return START_STICKY; } @ Override Public Empty OnDesto () {Super. Onsteroy (); Beacon history = null; MBeaconManager.unbind (this); } @Override Public beacon beacon service connect () {mBeaconManager.setRangeNotifier (new resonantifier) ​​{@Override Public Canceled TharrenzbeckinsEragian (collection  beacon, area area) {if (ActivityBase.isActivityVisible () ) {// do not do that logic if any activity from my app is in the foreground return;} ...}}}); Try {MBeaconManager.startRangingBeaconsInRegion (fieldmeter); } Hold (RemoteException E) {Log. A (tag, "beacon service", e); }}  

This is a case where a custom android.app Application class is very useful Beacon Manager is a singleton so there is permission to be present at the same time. Similarly, the app is an example of an active Android application per class. If you want to find beacon in a activity and a service , then the centralized application class for bike manager Use to force and then send callback to both your activity and your service .

You can see an example of compelling . BeaconManager is passing callback to activity in a application class and then in a reference:


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -