petermetz / cordova-plugin-ibeacon

An iBeacon plugin for Phonegap / Cordova 3.x and upwards. Supports both iOS and Android (contributions are welcome)
Apache License 2.0
726 stars 373 forks source link

There is no "com.unarin.cordova.beacon.IBeaconPlugin.DID_MONITORING" to work on android background. #108

Closed gnustory closed 9 years ago

gnustory commented 9 years ago

Hi there. I test this plugin on android background. It could't work.

As i think. There is no "com.unarin.cordova.beacon.IBeaconPlugin.DID_MONITORING" and "com.unarin.cordova.beacon.IBeaconPlugin.DID_RANGING" to work on android background.

"com.unarin.cordova.beacon.IBeaconPlugin.DID_MONITORING" is mentioned at the androidManifext.xml. (about 13 ~ 19 line in the IBeaconIntentProcessor tag)

    <service android:enabled="true" android:name="com.radiusnetworks.ibeacon.IBeaconIntentProcessor">
        <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>

Do you have any idea to solve it?

I want to run beacon plugin on android background service.

Thanks a lot.

mrtree1 commented 9 years ago

Those action names are just unique strings used to specify actions for the library uniquely, they don't represent anything other than just a string. The manifest details were just copied from sample usage of the (now deleted) Radius iBeacon library. I think it might be a legacy that was never tidied up as I can't see those actions are used at all, but the library definitely should work in background as it actively checks if it's running in background and slows down the scan rate if so. The default background scan rate is every 5 minutes, so you might not be waiting long enough?

At some point our plugin will get a proper upgrade to the AltBeacon library (which is what Radius now support), but until then, the underlying library will remain as is.

gnustory commented 9 years ago

Thank you for your reply

I am very happy to hear that beacon plugin works in android background service.

I want to set background scan rate. How could i set background scan rate?

We need to set a short time in background scan rate.

Thanks a lot.

mrtree1 commented 9 years ago

I've not tried it, and it's not exposed in the plugin but if you need to set the backround scan rate you could edit the initLocationManager method in LocationManager.java file, and add this line to the end of that function:

iBeaconManager.setBackgroundBetweenScanPeriod(scanInMilliseconds);

where scanInMilliseconds is your gap between scans.