Android background service Cordova plugin to Monitor Beacons -


update:

i got working on different phone. don't know if issue library or phone or android version. phone failing on blu advance 4.0 l2 running android 6.0. tested on other phone running android 5.1 , works fine on that. can explain why might happening?

i created basic background service plugin monitor beacons on android when app killed. running strange issue. beacon monitoring works fine when app in background/foreground, when kill app service keeps running beacon monitoring stops working! monitoring starts working again open next time. using altbeacon library. noticed kill app, beaconmanager becomes null, , doesn't bind again until start app.

@override public int onstartcommand(intent intent, int flags, int startid) {     super.onstartcommand(intent, flags, startid);     log.d(tag, "onstartcommand run");      initialiseservice();      beaconmanager = beaconmanager.getinstanceforapplication(this.getapplicationcontext());     // detect proprietary beacons, must add line below corresponding beacon     // type.  web search "setbeaconlayout" proper expression.     beaconmanager.getbeaconparsers().add(new beaconparser().             setbeaconlayout(_beaconlayout));     beaconmanager.bind(this);      return start_sticky;   } 

i start monitoring inside onbeaconserviceconnect()

@override     public void onbeaconserviceconnect() {         isinitialized = true;         lastmessage = "beacon service connected";         send();         beaconmanager.setmonitornotifier(new monitornotifier() {              @override             public void didenterregion(region region) {                 lastmessage = "i saw beacon first time!";                 //sendmessage();                 send();                 log.i(tag, lastmessage);             }              @override             public void didexitregion(region region) {                 lastmessage = "i no longer see beacon";                 //sendmessage();                 send();                 log.i(tag, lastmessage);             }              @override             public void diddeterminestateforregion(int state, region region) {                 lastmessage = "i have switched seeing/not seeing beacons: "+state;                 log.i(tag, lastmessage);             }         });          beaconmanager.setrangenotifier(new rangenotifier() {             @override             public void didrangebeaconsinregion(collection<beacon> beacons, region region) {                 if (beacons.size() > 0) {                     //send();                     log.i(tag, "the first beacon see "+beacons.iterator().next().getdistance()+" meters away.");                 }             }         });          try {             beaconmanager.startmonitoringbeaconsinregion(new region("mymonitoringuniqueid", null, null, null));             beaconmanager.startrangingbeaconsinregion(new region("myranginguniqueid", null, null, null));         } catch (remoteexception e) {    }      } 

this plugin tried using - github.com/lulibrary/background-beacon-monitoring seeing same behavior plugin also. after kill app service restarts , beaconmanager doesn't bind.

here android manifest below:

<?xml version='1.0' encoding='utf-8'?> <manifest android:hardwareaccelerated="true" android:versioncode="10000" android:versionname="1.0.0" package="com.example.sample" xmlns:android="http://schemas.android.com/apk/res/android">     <supports-screens android:anydensity="true" android:largescreens="true" android:normalscreens="true" android:resizeable="true" android:smallscreens="true" android:xlargescreens="true" />     <application android:hardwareaccelerated="true" android:icon="@mipmap/icon" android:label="@string/app_name" android:supportsrtl="true">         <activity android:configchanges="orientation|keyboardhidden|keyboard|screensize|locale" android:label="@string/activity_name" android:launchmode="singletop" android:name="mainactivity" android:theme="@android:style/theme.devicedefault.noactionbar" android:windowsoftinputmode="adjustresize">             <intent-filter android:label="@string/launcher_name">                 <action android:name="android.intent.action.main" />                 <category android:name="android.intent.category.launcher" />             </intent-filter>         </activity>         <receiver android:name="uk.ac.lancaster.library.backgroundbeacons.startupbroadcastreceiver">             <intent-filter>                 <action android:name="android.intent.action.boot_completed" />                 <action android:name="android.intent.action.action_power_connected" />                 <action android:name="android.intent.action.action_power_disconnected" />             </intent-filter>         </receiver>         <service android:enabled="true" android:exported="true" android:isolatedprocess="false" android:label="myjourneysbackgroundbeaconservice" android:name="uk.ac.lancaster.library.backgroundbeacons.backgroundbeaconservice" />         <receiver android:name="org.altbeacon.beacon.startup.startupbroadcastreceiver">             <intent-filter>                 <action android:name="android.intent.action.boot_completed" />                 <action android:name="android.intent.action.action_power_connected" />                 <action android:name="android.intent.action.action_power_disconnected" />             </intent-filter>         </receiver>         <service android:enabled="true" android:exported="true" android:isolatedprocess="false" android:label="ibeacon" android:name="org.altbeacon.beacon.service.beaconservice" />         <service android:enabled="true" android:name="org.altbeacon.beacon.beaconintentprocessor">             <meta-data android:name="background" android:value="true" />             <intent-filter android:priority="1">                 <action android:name="com.unarin.cordova.beacon.ibeaconplugin.did_ranging" />                 <action android:name="com.unarin.cordova.beacon.ibeaconplugin.did_monitoring" />             </intent-filter>         </service>     </application>     <uses-sdk android:minsdkversion="16" android:targetsdkversion="24" />     <uses-permission android:name="android.permission.internet" />     <uses-permission android:name="android.permission.access_network_state" />     <uses-permission android:name="android.permission.bluetooth" />     <uses-permission android:name="android.permission.bluetooth_admin" />     <uses-permission android:name="android.permission.read_external_storage" />     <uses-permission android:name="android.permission.access_coarse_location" />     <uses-permission android:name="android.permission.receive_boot_completed" /> </manifest> 


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -