Hi everyone
I'm happy to introduce a new library to Basic4Android.
Drop this tiny library into your Android app, configure your manifest, initialise it in your application's .. and that's it!
Location updates will be broadcast to your app periodically, including after phone reboot. And your users won't complain about it killing their batteries.
Perfect for widgets that require periodic updates in background, and for apps that need a reasonably current location available to them on startup. Also works great for apps that do something with location periodically, such as using it to get updates from a server.
Requires Android 2.1 and up. Works best with 2.2 and up.
The library works by using Froyo's passive location listener (only possible with Android 2.2 and up, hence why it works best with it), which listens to location updates requested by other apps on your phone. The most accurate location is broadcast to your app approximately every 15 minutes. If a location update hasn't been received from another app for an hour, the library forces a location update of its own.
The original library is written by Kenton Price, co-founder of Little Fluffy Toys Ltd.
Features:
API Documentation
Manifest:
Change "com.rootsoft.rsfluffylocation" to your own package name.
Kind regard,
Tomas
RootSoft LLC
I'm happy to introduce a new library to Basic4Android.
Drop this tiny library into your Android app, configure your manifest, initialise it in your application's .. and that's it!
Location updates will be broadcast to your app periodically, including after phone reboot. And your users won't complain about it killing their batteries.
Perfect for widgets that require periodic updates in background, and for apps that need a reasonably current location available to them on startup. Also works great for apps that do something with location periodically, such as using it to get updates from a server.
Requires Android 2.1 and up. Works best with 2.2 and up.
The library works by using Froyo's passive location listener (only possible with Android 2.2 and up, hence why it works best with it), which listens to location updates requested by other apps on your phone. The most accurate location is broadcast to your app approximately every 15 minutes. If a location update hasn't been received from another app for an hour, the library forces a location update of its own.
The original library is written by Kenton Price, co-founder of Little Fluffy Toys Ltd.
Features:
- location updates broadcast to your app approximately every 15 minutes (if a new location update was found)
- if no location update found for an hour, an update is requested
- optionally, every location update is broadcast
- frequency of regular broadcasts (default 15 minutes) and forced updates (default 60 minutes) configurable
- force update feature
- get latest location feature
- choose the most accurate location from the location providers available
- debug output optional
API Documentation
RSFluffyLocation
Author: XverhelstX
Version: 1
- RSFluffyLocation
Fields:Methods:
- DEFAULT_ALARM_FREQUENCY As Long
- DEFAULT_MAXIMUM_LOCATION_AGE As Int
- LOCATION_BROADCAST_EXTRA_LOCATIONINFO As String
- getLocationChangedPeriodicBroadcastAction As String
- getLocationChangedTickerBroadcastAction As String
Permissions:
- EnableDebugging
- ForceLocationUpdate
To force a location update, call this and soon you'll get a broadcast containing the latest location.- Initialize (PackageName As String) As Int
Initializes the RSFluffylocation Library.
PackageName - Your package name of your app.- Initialize2 (PackageName As String, BroadcastEveryLocationUpdate As Boolean) As Int
Initializes the RSFluffylocation Library.
PackageName - Your package name of your app.
BroadcastEveryLocationUpdate - If true, in addition to broadcasting periodic updates,
it broadcasts every location update as it is found,
using intent action com.your.package.name.littlefluffylocationlibrary.LOCATION_CHANGED_TICK. The default is false- Initialize3 (PackageName As String, AlarmFrequency As Long, LocationMaximumAge As Int) As Int
Initializes the RSFluffylocation Library.
PackageName - Your package name of your app.
AlarmFrequency - How often to broadcast a location update in milliseconds, if one was received.
For battery efficiency, this should be one of the available inexact recurrence intervals.
You are not prevented from using any other value.The default is AlarmManager.INTERVAL_FIFTEEN_MINUTES.
LocationMaximumAge - The maximum age of a location update.
If when the alarm fires the location is older than this, a location update will be requested.
The default is AlarmManager.INTERVAL_HOUR.- Initialize4 (PackageName As String, BroadcastEveryLocationUpdate As Boolean, AlarmFrequency As Long, LocationMaximumAge As Int) As Int
Initializes the RSFluffylocation Library.
PackageName - Your package name of your app.
BroadcastEveryLocationUpdate - If true, in addition to broadcasting periodic updates,
it broadcasts every location update as it is found,
using intent action com.your.package.name.littlefluffylocationlibrary.LOCATION_CHANGED_TICK. The default is false
AlarmFrequency - How often to broadcast a location update in milliseconds, if one was received.
For battery efficiency, this should be one of the available inexact recurrence intervals.
You are not prevented from using any other value.The default is AlarmManager.INTERVAL_FIFTEEN_MINUTES.
LocationMaximumAge - The maximum age of a location update.
If when the alarm fires the location is older than this, a location update will be requested.
The default is AlarmManager.INTERVAL_HOUR.- UseFineAccuracyForRequests (useFineAccuracyForRequests As Boolean)
Uses fine accuracy for requests.- getLocationInfo (intent As IntentWrapper) As LocationInfo
Returns the latest LocationInfo object from an intent.
You should call this from your BroadCastReceiver OnReceive method.
- android.permission.ACCESS_COARSE_LOCATION
- android.permission.ACCESS_FINE_LOCATION
- android.permission.RECEIVE_BOOT_COMPLETED
- RSFluffyLocationInfo
Methods:Properties:
- AnyLocationDataBroadcast As Boolean
Returns true if any location data been broadcast since the last reboot- AnyLocationDataReceived As Boolean
Returns true if any location data been received since the last reboot.- HasLatestDataBeenBroadcast As Boolean
Returns true if the location data in the object has already been broadcast.- Initialize
Initializes the RSFluffylocation Library.
PackageName - Your package name of your app.- IsInitialized As Boolean
- Refresh
Refresh the fields with the latest location info
- Accuracy As Int [read only]
Gets the last location update's accuracy, in metres- Latitude As Float [read only]
Gets the last location update's latitude.- LocationBroadcastTimestamp As Long [read only]
Gets the time a location update was last broadcast, in milliseconds- LocationUpdateTimestamp As Long [read only]
Gets the time the last location update was recorded, in milliseconds- Longitude As Float [read only]
Gets the last location update's longitude- Provider As String [read only]
Gets the latest location provider.- TimestampAgeInSeconds As Long [read only]
Returns the age of the last location update in seconds
Manifest:
B4X:
AddManifestText(
<uses-feature android:name="android.hardware.location" android:required="true" />
<uses-feature android:name="android.hardware.location.gps" android:required="false" />
)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
'End of default text.
AddReceiverText(LocationListener,
<intent-filter>
<action android:name="com.rootsoft.rsfluffylocation.littlefluffylocationlibrary.LOCATION_CHANGED" />
<action android:name="com.rootsoft.rsfluffylocation.littlefluffylocationlibrary.LOCATION_CHANGED_TICK" />
</intent-filter>)
AddApplicationText(
<service android:name="com.littlefluffytoys.littlefluffylocationlibrary.LocationBroadcastService" />
<receiver android:name="com.littlefluffytoys.littlefluffylocationlibrary.StartupBroadcastReceiver" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<receiver android:name="com.littlefluffytoys.littlefluffylocationlibrary.PassiveLocationChangedReceiver" android:exported="true" />
)
Change "com.rootsoft.rsfluffylocation" to your own package name.
Kind regard,
Tomas
RootSoft LLC
Attachments
Last edited: