Right here's an update on the LocationAPI library - sorry for the delays, been pretty busy with lots of things here.
This update is i think how i plan to keep the library, previously posted alpha versions of the library and previously posted code examples will need modifying.
The main change is the removal of the OnAddGeofencesResultListener and OnRemoveGeofencesResultListener.
Events previously raised by these objects (when adding or removing Geofences) are now raised by the LocationClient.
Here's the reference for the latest version:
LocationAPI
Version: 0.05 alpha
- ActivityRecognitionClient
Events:
- Connected
- ConnectionFailed (ErrorCode As Int)
- Disconnected
Methods:
- Connect
Connects the client to Google Play services.
- Disconnect
Closes the connection to Google Play services.
- Initialize (EventName As String)
- IsConnected As Boolean
Checks if the client is currently connected to the service, so that requests to other methods will succeed.
- IsConnecting As Boolean
Checks if the client is attempting to connect to the service.
- IsInitialized As Boolean
- RemoveActivityUpdates (PendingIntent1 As PendingIntent)
Removes all activity updates for the specified PendingIntent.
- RequestActivityUpdates (DetectionIntervalMillis As Long, PendingIntent1 As PendingIntent)
Register for activity recognition updates.
Permissions:
- com.google.android.gms.permission.ACTIVITY_RECOGNITION
- ActivityRecognitionResult
Methods:
- GetActivityConfidence (ActivityType As Int) As Int
Returns the confidence of the given activity type.
- GetElapsedRealtimeMillis As Long
Returns the elapsed real time of this detection in milliseconds since boot,
including time spent in sleep as obtained by SystemClock.elapsedRealtime().
- GetMostProbableActivity As DetectedActivity
Returns the most probable activity of the user.
- GetProbableActivities As List
Returns a list of activities that where detected with the confidence value associated with each activity.
- GetTime As Long
Returns the UTC time of this detection, in milliseconds since January 1, 1970.
- Initialize (Intent1 As Intent) As Boolean
Initialize the ActivityRecognitionResult from Intent1.
If Intent1 contains no ActivityRecognitionResult then the ActivityRecognitionResult will not be initialized and this method will return False.
Otherwise ActivityRecognitionResult will be initialized and this method will return True.
- IsInitialized As Boolean
- DetectedActivity
Fields:
- IN_VEHICLE As Int
The device is in a vehicle, such as a car.
- ON_BICYCLE As Int
The device is on a bicycle.
- ON_FOOT As Int
The device is on a user who is walking or running.
- STILL As Int
The device is still (not moving).
- TILTING As Int
The device angle relative to gravity changed significantly.
This often occurs when a device is picked up from a desk or a user who is sitting stands up.
- UNKNOWN As Int
Unable to detect the current activity.
Methods:
- GetConfidence As Int
Returns a value from 0 to 100 indicating the likelihood that the user is performing this activity.
The larger the value, the more consistent the data used to perform the classification is with the detected activity.
The sum of the confidences of all detected activities for a classification will be <= 100.
This means that larger values such as a confidence of >= 75 indicate that it's very likely that the detected activity is correct,
while a value of <= 50 indicates that there may be another activity that is just as or more likely.
- GetType As Int
Returns the type of activity that was detected.
- Initialize (ActivityType As Int, Confidence As Int)
Initialize the DetectedActivity.
- IsInitialized As Boolean
- Geofence
Fields:
- GEOFENCE_TRANSITION_ENTER As Int
The transition type indicating that the user enters the geofence(s).
- GEOFENCE_TRANSITION_EXIT As Int
The transition type indicating that the user exits the geofence(s).
- NEVER_EXPIRE As Long
Expiration value that indicates the geofence should never expire.
Methods:
- GetRequestId As String
Returns the request ID of this geofence.
- IsInitialized As Boolean
- GeofenceBuilder
Methods:
- Build As Geofence
Creates a Geofence object.
- Initialize
Initialize the GeofenceBuilder.
- IsInitialized As Boolean
- SetCircularRegion (Latitude As Double, Longitude As Double, Radius As Float) As GeofenceBuilder
Sets the region of the geofence.
Latitude - latitude in degrees, between -90 and +90 inclusive.
Longitude - longitude in degrees, between -180 and +180 inclusive.
Radius - radius in meters.
- SetExpirationDuration (DurationMillis As Long) As GeofenceBuilder
Sets the expiration duration of the geofence.
The geofence will be removed automatically after this period of time.
When two geofences with the same requestId are monitored,
the new one will replace the old one regardless the geographical region these two geofences represent.
- SetRequestId (RequestId As String) As GeofenceBuilder
Sets the request ID of the geofence.
Request ID is a string to identify the geofence inside your application.
- SetTransitionTypes (TransitionTypes As Int) As GeofenceBuilder
Sets the transition types of interest.
Alerts are only generated for the given transition types.
TransitionTypes - a bitwise-OR of GEOFENCE_TRANSITION_ flags.
- GooglePlayServicesHelper
Fields:
- DEVELOPER_ERROR As Int
- INTERNAL_ERROR As Int
- INVALID_ACCOUNT As Int
- LICENSE_CHECK_FAILED As Int
- NETWORK_ERROR As Int
- RESOLUTION_REQUIRED As Int
- SERVICE_DISABLED As Int
- SERVICE_INVALID As Int
- SERVICE_MISSING As Int
- SERVICE_VERSION_UPDATE_REQUIRED As Int
- SIGN_IN_REQUIRED As Int
- SUCCESS As Int
Methods:
- IsGooglePlayServicesAvailable As Int
Verifies that Google Play services is installed and enabled on this device,
and that the version installed on this device is no older than the one required by this client.
- LocationClient
Events:
- AddGeofencesResult (StatusCode As Int, GeofenceRequestIds() As String)
- Connected
- ConnectionFailed (ErrorCode As Int)
- Disconnected
- RemoveGeofencesByRequestIdsResult (StatusCode As Int, GeofenceRequestIds() As String)
Methods:
- AddGeofences (Geofences As List, PendingIntent1 As PendingIntent)
Sets alerts to be notified when the device enters or exits one of the specified geofences.
- Connect
Connects the client to Google Play services.
- Disconnect
Closes the connection to Google Play services.
- GetErrorCode (Intent1 As Intent) As Int
Returns the error code that explains the error that triggered Intent1.
- GetGeofenceTransition (Intent1 As Intent) As Int
Returns the transition type of geofence transition alert.
- GetLastLocation As LocationWrapper
Returns the best most recent location currently available.
The returned Location object will be uninitialized if no last location is available.
- GetTriggeringGeofences (Intent1 As Intent) As Geofence[]
Returns an Array of Geofence objects that triggered this geofence transition alert.
- HasError (Intent1 As Intent) As Boolean
Whether an error triggered Intent1.
- Initialize (EventName As String)
- IsConnected As Boolean
Checks if the client is currently connected to the service, so that requests to other methods will succeed.
- IsConnecting As Boolean
Checks if the client is attempting to connect to the service.
- IsInitialized As Boolean
- RemoveGeofences (GeofenceIds As List)
Removes geofences by their request IDs.
- RemoveLocationUpdates (LocationListener1 As LocationListener)
Removes all location updates.
- RequestLocationUpdates (LocationRequest1 As LocationRequest, LocationListener1 As LocationListener)
Requests location updates.
Permissions:
- android.permission.ACCESS_FINE_LOCATION
- LocationListener
Events:
- LocationChanged (Location1 As Location)
Methods:
- Initialize (EventName As String)
- IsInitialized As Boolean
- LocationRequest
Fields:
- PRIORITY_BALANCED_POWER_ACCURACY As Int
Used with SetPriority(Int) to request "block" level accuracy.
- PRIORITY_HIGH_ACCURACY As Int
Used with SetPriority(Int) to request the most accurate locations available.
- PRIORITY_NO_POWER As Int
Used with SetPriority(Int) to request the best accuracy possible with zero additional power consumption.
Methods:
- GetExpirationTime As Long
Get the request expiration time, in milliseconds since boot.
- GetFastestInterval As Long
Get the fastest interval of this request, in milliseconds.
- GetInterval As Long
Get the desired interval of this request, in milliseconds.
- GetNumUpdates As Int
Get the number of updates requested.
- GetPriority As Int
Get the quality of the request.
- GetSmallestDisplacement As Float
Get the minimum displacement between location updates in meters.
By default this is 0.
- Initialize
Initialize the LocationRequest with default parameters.
- IsInitialized As Boolean
- SetExpirationDuration (Millis As Long) As LocationRequest
Set the duration of this request, in milliseconds.
- SetExpirationTime (Millis As Long) As LocationRequest
Set the request expiration time, in millisecond since boot.
- SetFastestInterval (Millis As Long) As LocationRequest
Explicitly set the fastest interval for location updates, in milliseconds.
- SetInterval (Millis As Long) As LocationRequest
Set the desired interval for active location updates, in milliseconds.
- SetNumUpdates (NumUpdates As Int) As LocationRequest
Set the number of location updates.
- SetPriority (Priority As Int) As LocationRequest
Set the priority of the request.
- SetSmallestDisplacement (SmallestDisplacementMeters As Float) As LocationRequest
Set the minimum displacement between location updates in meters.
By default this is 0.
- LocationStatusCodes
Fields:
- ERROR As Int
An unspecified error occurred; no more specific information is available.
- GEOFENCE_NOT_AVAILABLE As Int
Geofence service is not available now.
- GEOFENCE_TOO_MANY_GEOFENCES As Int
Your app has registered more than 100 geofences.
- GEOFENCE_TOO_MANY_PENDING_INTENTS As Int
You have provided more than 5 different PendingIntents to the addGeofences(List, PendingIntent, OnAddGeofencesResultListener) call.
- SUCCESS As Int
The operation was successful.
- PendingIntent
Fields:
- FLAG_CANCEL_CURRENT As Int
If the described PendingIntent already exists, the current one is cancelled before generating a new one.
- FLAG_NO_CREATE As Int
If the described PendingIntent does not already exist, then simply return null instead of creating it.
- FLAG_ONE_SHOT As Int
This PendingIntent can only be used once.
- FLAG_UPDATE_CURRENT As Int
If the described PendingIntent already exists, then keep it but its replace its extra data with what is in this new Intent.
Methods:
- Cancel
Cancel a currently active PendingIntent.
- InitializeActivity (RequestCode As Int, Intent1 As Intent, Flags As Int)
- InitializeBroadcast (RequestCode As Int, Intent1 As Intent, Flags As Int)
- InitializeService (RequestCode As Int, Intent1 As Intent, Flags As Int)
- IsInitialized As Boolean
From the tests i have done and from what netchicken has reported i think the library will provide a reliable way to get the device location using varying degrees of accuracy and varying degrees of battery power.
Actitivy detection seems to be pretty useable too.
That leaves the Geofence detection which i have to say i am not at all impressed with!
My tests have sometimes shown it to work but mostly it has let me down.
As i've previously posted this is not a problem with the b4a library but a problem with the Location APIs that it wraps - the native java android Location API's Geofence detection has more than a few reports of not working as described in the documentation.
The latest (alpha) version of the library is attached, i shall post code examples for LocationClient and ActivityRecognitionClient to show basic usage and then do some more tests with the Geofence detection.
Hopefully i can find a way to improve Geofence detection and i'll then post a code example for that.
Martin.