Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
cordova-background-geolocation
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Aksimaya
cordova-background-geolocation
Commits
4a387fba
Commit
4a387fba
authored
Apr 10, 2015
by
Chris Scott
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #16 from christocracy/configurable_location_request
Configurable location request
parents
ae05c066
dd4a0e2d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
8 deletions
+41
-8
BackgroundGeolocationService.java
src/android/BackgroundGeolocationService.java
+41
-8
No files found.
src/android/BackgroundGeolocationService.java
View file @
4a387fba
...
...
@@ -77,6 +77,10 @@ public class BackgroundGeolocationService extends Service implements GoogleApiCl
* @config {Integer} locationUpdateInterval (ms)
*/
private
Integer
locationUpdateInterval
=
60000
;
/**
* @config {Integer} fastestLocationUpdateInterval (ms)
*/
private
Integer
fastestLocationUpdateInterval
=
30000
;
/**
* @config {Integer{ activityRecognitionInterval (ms)
*/
...
...
@@ -193,14 +197,7 @@ public class BackgroundGeolocationService extends Service implements GoogleApiCl
@Override
public
void
onConnected
(
Bundle
arg0
)
{
Log
.
i
(
TAG
,
"- GooglePlayServices connected"
);
// Configure FusedLocationProvider
locationRequest
=
LocationRequest
.
create
()
.
setPriority
(
translateDesiredAccuracy
(
desiredAccuracy
))
.
setInterval
(
this
.
locationUpdateInterval
)
.
setFastestInterval
(
30000
)
.
setSmallestDisplacement
(
distanceFilter
);
Intent
arsIntent
=
new
Intent
(
this
,
ActivityRecognitionService
.
class
);
activityRecognitionPI
=
PendingIntent
.
getService
(
this
,
0
,
arsIntent
,
PendingIntent
.
FLAG_UPDATE_CURRENT
);
...
...
@@ -367,6 +364,34 @@ public class BackgroundGeolocationService extends Service implements GoogleApiCl
return
accuracy
;
}
private
Integer
getLocationUpdateInterval
()
{
// TODO Can add intelligence here based upon currentActivity.
return
locationUpdateInterval
;
}
private
Integer
getFastestLocationUpdateInterval
()
{
/* TODO Add intelligent calculation of fastestLocationUpdateInterval based upon currentActivity here
* switch (currentActivity.getType()) {
case DetectedActivity.IN_VEHICLE:
fastestLocationUpdateInterval = 30000;
break;
case DetectedActivity.ON_BICYCLE:
fastestLocationUpdateInterval = 30000;
break;
case DetectedActivity.ON_FOOT:
fastestLocationUpdateInterval = 30000;
break;
case DetectedActivity.RUNNING:
fastestLocationUpdateInterval = 30000;
break;
case DetectedActivity.WALKING:
fastestLocationUpdateInterval = 30000;
break;
}
*/
return
fastestLocationUpdateInterval
;
}
private
String
getActivityName
(
int
activityType
)
{
switch
(
activityType
)
{
case
DetectedActivity
.
IN_VEHICLE
:
...
...
@@ -479,6 +504,14 @@ public class BackgroundGeolocationService extends Service implements GoogleApiCl
private
void
requestLocationUpdates
()
{
if
(!
isPaused
||
!
isEnabled
)
{
return
;
}
// <-- Don't engage GPS when app is in foreground
// Configure LocationRequest
locationRequest
=
LocationRequest
.
create
()
.
setPriority
(
translateDesiredAccuracy
(
desiredAccuracy
))
.
setInterval
(
getLocationUpdateInterval
())
.
setFastestInterval
(
getFastestLocationUpdateInterval
())
.
setSmallestDisplacement
(
distanceFilter
);
LocationServices
.
FusedLocationApi
.
requestLocationUpdates
(
googleApiClient
,
locationRequest
,
locationUpdatePI
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment