android - How do I implement background service for kontakt.io sdk? -


To

I want to display a notification I entered an area of ​​the beacon with your Android device. Thats well documented on

It's working just as long as the app is active. When the app gets notifications closing?

I build one yourself service:

< strong> BeaconRangingService.java

  public class BeaconRangingService extends Service {private static final string tag = BeaconRangingService.class.getSimpleName (); Private Beacon Manager Beacon Manager; @ Override Public Empty on Create () {Super. Connet (); Beacon Manager = Beacon Manager. New Instance (getApplicationContext ()); BeaconManager.setMonitorPeriod (MonitorPeriod.MINIMAL); BeaconManager.setForceScanConfiguration (ForceScanConfiguration.DEFAULT); beaconManager.registerMonitoringListener (New BeaconManager.MonitoringListener () {@Override public void onMonitorStart () {Log.v (TAG, "start beacon monitoring");} @Override public void onMonitorStop () {Log.wtf (TAG, "Close monitoring Beacon ");} @Override public void onBeaconsUpdated (region list & list lt; Beacon & gt;) {} @Override public void onBeaconAppeared (area, Beacon) {Toast.makeText (getApplicationContext ()," Beacon appeared beacon ID \ n: "+ beacon.getBeaconUniqueId (), Toast.LENGTH_SHORT) .show ();} @Override public void onRegionEntered (region X Scripture) {} @Override public void onRegionAbandoned (field) {}}); } @Override Public Integer onStartCommand (intent, flags int, int startId) {Log.v (TAG, "service start"); If (beacon manager.blubootout- ()) {log.av (tag, "Bluetooth disabled, stop service"); StopSelf (); } And {connect (); } Return Super. Start Commands (Intent, Flags, Beginners); } @ Override public ibindor on bind (intent to intent) {return tap; } @ Override Public Wide On Destiny () {Log. V (tag, "service destroyed"); BeaconManager.stopMonitoring (); BeaconManager.disconnect (); Beacon manager = null; Super.onDestroy (); Region & gt; Areas = new HashSet & LT;} private void connectBeaconManager () {{beaconManager.connect (New OnServiceBoundListener () {@Override public void onServiceBound () {try {HashSet or & lt try & gt; (); regions.add (Region .EVERYWHERE); beaconManager.startMonitoring (area);} catch (RemoteException e) {e.printStackTrace ();}}}); } Grip (Remote Exception E) {New illegalast exception (E); }}}  

AndroidManifest.xml

  & lt; Service android: name = "com.your.package.BeaconRangingService" android: exported = "false" / & gt;  

Start Service

  Intent intent = new Intent (this, BeaconRangingService.class); StartService (intent);  

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -