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
1707abbd
Commit
1707abbd
authored
Apr 06, 2015
by
Chris Scott
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement paceChange method in new Service via EventBus
parent
8913484d
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
80 additions
and
35 deletions
+80
-35
index.js
example/SampleApp/www/js/index.js
+12
-7
plugin.xml
plugin.xml
+1
-1
ActivityRecognitionService.java
src/android/ActivityRecognitionService.java
+1
-1
BackgroundGeolocationPlugin.java
src/android/BackgroundGeolocationPlugin.java
+10
-7
BackgroundGeolocationService.java
src/android/BackgroundGeolocationService.java
+56
-19
No files found.
example/SampleApp/www/js/index.js
View file @
1707abbd
...
...
@@ -172,23 +172,28 @@ var app = {
// BackgroundGeoLocation is highly configurable.
bgGeo
.
configure
(
callbackFn
,
failureFn
,
{
debug
:
true
,
// <-- enable this hear sounds for background-geolocation life-cycle.
desiredAccuracy
:
0
,
stationaryRadius
:
50
,
distanceFilter
:
50
,
locationUpdateInterval
:
5000
,
activityRecognitionInterval
:
10000
,
stopTimeout
:
1
,
url
:
'
http://posttestserver.com/post.php?dir=cordova-background-geolocation
'
,
forceReload
:
true
,
// <-- If the user closes the app **while location-tracking is started** , reboot app (WARNING: possibly distruptive to user)
activityType
:
'
AutomotiveNavigation
'
,
stopOnTerminate
:
false
// <-- Allow the background-service to run headless when user closes the app.
/**
* HTTP Feature: set an url to allow the native background service to POST locations to your server
*
,url: 'http://posttestserver.com/post.php?dir=cordova-background-geolocation',
headers: {
"X-FOO": "bar"
},
params: {
"
auth_token
"
:
"
bar
"
},
forceReload
:
false
,
activityType
:
'
AutomotiveNavigation
'
,
debug
:
true
,
// <-- enable this hear sounds for background-geolocation life-cycle.
stopOnTerminate
:
false
// <-- enable this to clear background location settings when the app terminates
"auth_token": "maybe_your_server_authenticates_via_token_YES?"
}
*
*/
});
// Turn ON the background-geolocation system. The user will be tracked whenever they suspend the app.
...
...
plugin.xml
View file @
1707abbd
...
...
@@ -30,7 +30,7 @@
<source-file
src=
"src/android/ActivityRecognitionService.java"
target-dir=
"src/com/transistorsoft/cordova/bggeo"
/>
<source-file
src=
"src/android/LocationService.java"
target-dir=
"src/com/transistorsoft/cordova/bggeo"
/>
<!--
<!--
For SQLite persistence NOT YET IMPLEMENTED
<source-file src="src/android/data/LocationDAO.java" target-dir="src/com/tenforwardconsulting/cordova/bgloc/data" />
<source-file src="src/android/data/sqlite/LocationOpenHelper.java" target-dir="src/com/tenforwardconsulting/cordova/bgloc/data/sqlite" />
<source-file src="src/android/data/sqlite/SQLiteLocationDAO.java" target-dir="src/com/tenforwardconsulting/cordova/bgloc/data/sqlite" />
...
...
src/android/ActivityRecognitionService.java
View file @
1707abbd
...
...
@@ -24,7 +24,7 @@ public class ActivityRecognitionService extends IntentService {
ActivityRecognitionResult
result
=
ActivityRecognitionResult
.
extractResult
(
intent
);
DetectedActivity
probableActivity
=
result
.
getMostProbableActivity
();
Log
.
i
(
TAG
,
"Activity detected:"
+
getActivityName
(
probableActivity
.
getType
())
+
", confidence:"
+
probableActivity
.
getConfidence
());
Log
.
w
(
TAG
,
"Activity detected:"
+
getActivityName
(
probableActivity
.
getType
())
+
", confidence:"
+
probableActivity
.
getConfidence
());
if
(
probableActivity
.
getConfidence
()
<
80
)
{
return
;
}
...
...
src/android/BackgroundGeolocationPlugin.java
View file @
1707abbd
...
...
@@ -8,6 +8,8 @@ import org.json.JSONArray;
import
org.json.JSONObject
;
import
org.json.JSONException
;
import
com.transistorsoft.cordova.bggeo.BackgroundGeolocationService.PaceChangeEvent
;
import
com.transistorsoft.cordova.bggeo.BackgroundGeolocationService.PausedEvent
;
import
com.transistorsoft.cordova.bggeo.BackgroundGeolocationService.StationaryLocation
;
import
de.greenrobot.event.EventBus
;
...
...
@@ -38,8 +40,6 @@ public class BackgroundGeolocationPlugin extends CordovaPlugin {
private
CallbackContext
locationCallback
;
// Called when DetectedActivity is STILL
private
CallbackContext
stationaryCallback
;
private
Location
stationaryLocation
;
public
static
boolean
isActive
()
{
return
gWebView
!=
null
;
...
...
@@ -79,10 +79,13 @@ public class BackgroundGeolocationPlugin extends CordovaPlugin {
}
}
else
if
(
ACTION_ON_PACE_CHANGE
.
equalsIgnoreCase
(
action
))
{
if
(!
isEnabled
)
{
Log
.
w
(
TAG
,
"- Cannot change pace while
in #stop mode
"
);
Log
.
w
(
TAG
,
"- Cannot change pace while
disabled
"
);
result
=
false
;
callbackContext
.
error
(
"Cannot #changePace while in #stop mode"
);
}
else
{
callbackContext
.
error
(
"Cannot #changePace while disabled"
);
}
else
{
PaceChangeEvent
event
=
new
PaceChangeEvent
(
data
.
getBoolean
(
0
));
EventBus
.
getDefault
().
post
(
event
);
result
=
true
;
callbackContext
.
success
();
}
...
...
@@ -157,12 +160,13 @@ public class BackgroundGeolocationPlugin extends CordovaPlugin {
Log
.
i
(
TAG
,
"- onPause"
);
if
(
isEnabled
)
{
//setPace(isMoving);
EventBus
.
getDefault
().
post
(
new
PausedEvent
(
true
));
}
}
public
void
onResume
(
boolean
multitasking
)
{
Log
.
i
(
TAG
,
"- onResume"
);
if
(
isEnabled
)
{
//removeLocationUpdates(
);
EventBus
.
getDefault
().
post
(
new
PausedEvent
(
false
)
);
}
}
...
...
@@ -175,7 +179,6 @@ public class BackgroundGeolocationPlugin extends CordovaPlugin {
result
.
setKeepCallback
(
true
);
if
(
location
instanceof
StationaryLocation
)
{
stationaryLocation
=
location
;
if
(
stationaryCallback
!=
null
)
{
runInBackground
(
stationaryCallback
,
result
);
}
...
...
src/android/BackgroundGeolocationService.java
View file @
1707abbd
...
...
@@ -35,8 +35,6 @@ import android.os.AsyncTask;
import
android.os.Build
;
import
android.os.Bundle
;
import
android.os.IBinder
;
import
android.os.PowerManager
;
import
android.os.PowerManager.WakeLock
;
import
android.util.Log
;
public
class
BackgroundGeolocationService
extends
Service
implements
GoogleApiClient
.
ConnectionCallbacks
,
GoogleApiClient
.
OnConnectionFailedListener
{
...
...
@@ -49,7 +47,6 @@ public class BackgroundGeolocationService extends Service implements GoogleApiCl
}
private
GoogleApiClient
googleApiClient
;
private
WakeLock
wakeLock
;
private
ToneGenerator
toneGenerator
;
private
PendingIntent
activityRecognitionPI
;
...
...
@@ -109,6 +106,8 @@ public class BackgroundGeolocationService extends Service implements GoogleApiCl
// Flags
private
Boolean
isEnabled
=
false
;
private
Boolean
isMoving
=
false
;
private
Boolean
isPaused
=
true
;
private
long
stoppedAt
=
0
;
private
Location
stationaryLocation
;
...
...
@@ -116,7 +115,6 @@ public class BackgroundGeolocationService extends Service implements GoogleApiCl
@Override
public
int
onStartCommand
(
Intent
intent
,
int
flags
,
int
startId
)
{
Log
.
i
(
TAG
,
"- Start BackgroundGeolocationService"
);
instance
=
this
;
EventBus
.
getDefault
().
register
(
this
);
...
...
@@ -127,10 +125,10 @@ public class BackgroundGeolocationService extends Service implements GoogleApiCl
distanceFilter
=
intent
.
getFloatExtra
(
"distanceFilter"
,
50
);
desiredAccuracy
=
intent
.
getIntExtra
(
"desiredAccuracy"
,
10
);
locationUpdateInterval
=
intent
.
getIntExtra
(
"locationUpdateInterval"
,
30000
);
activityRecognitionInterval
=
intent
.
getIntExtra
(
"activityRecognitionInterval"
,
1
0000
);
activityRecognitionInterval
=
intent
.
getIntExtra
(
"activityRecognitionInterval"
,
6
0000
);
stopTimeout
=
intent
.
getLongExtra
(
"stopTimeout"
,
0
);
forceReload
=
intent
.
getBooleanExtra
(
"forceReload"
,
false
);
// HTTP Configuration
url
=
intent
.
getStringExtra
(
"url"
);
try
{
...
...
@@ -144,6 +142,17 @@ public class BackgroundGeolocationService extends Service implements GoogleApiCl
e
.
printStackTrace
();
}
Log
.
i
(
TAG
,
"----------------------------------------"
);
Log
.
i
(
TAG
,
"- Start BackgroundGeolocationService"
);
Log
.
i
(
TAG
,
" debug: "
+
isDebugging
);
Log
.
i
(
TAG
,
" distanceFilter: "
+
distanceFilter
);
Log
.
i
(
TAG
,
" desiredAccuracy: "
+
desiredAccuracy
);
Log
.
i
(
TAG
,
" locationUpdateInterval: "
+
locationUpdateInterval
);
Log
.
i
(
TAG
,
" activityRecognitionInterval: "
+
activityRecognitionInterval
);
Log
.
i
(
TAG
,
" stopTimeout: "
+
stopTimeout
);
Log
.
i
(
TAG
,
" forceReload: "
+
forceReload
);
Log
.
i
(
TAG
,
"----------------------------------------"
);
// For debug sounds, turn on ToneGenerator.
if
(
isDebugging
)
{
toneGenerator
=
new
ToneGenerator
(
AudioManager
.
STREAM_NOTIFICATION
,
100
);
...
...
@@ -172,12 +181,6 @@ public class BackgroundGeolocationService extends Service implements GoogleApiCl
Log
.
e
(
TAG
,
"- GooglePlayServices unavailable"
);
}
/*
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
wakeLock.acquire();
*/
return
Service
.
START_REDELIVER_INTENT
;
}
...
...
@@ -208,6 +211,29 @@ public class BackgroundGeolocationService extends Service implements GoogleApiCl
}
}
/**
* EventBus listener
* Fired from Plugin
* @param {PausedEvent} event
*/
public
void
onEventMainThread
(
PausedEvent
event
)
{
isPaused
=
event
.
isPaused
;
if
(
isPaused
)
{
setPace
(
isMoving
);
}
else
{
removeLocationUpdates
();
}
}
/**
* EventBus listener
* Fired from Plugin
* @param {PaceChangeEvent} event
*/
public
void
onEventMainThread
(
PaceChangeEvent
event
)
{
setPace
(
event
.
isMoving
);
}
/**
* EventBus listener for ARS
* @param {ActivityRecognitionResult} result
...
...
@@ -215,7 +241,7 @@ public class BackgroundGeolocationService extends Service implements GoogleApiCl
public
void
onEventMainThread
(
ActivityRecognitionResult
result
)
{
currentActivity
=
result
.
getMostProbableActivity
();
String
probableActivityName
=
getActivityName
(
currentActivity
.
getType
());
Log
.
w
(
TAG
,
"- DetectedActivity
: "
+
probableActivityName
+
", confidence: "
+
currentActivity
.
getConfidence
());
Log
.
i
(
TAG
,
"- Activity received
: "
+
probableActivityName
+
", confidence: "
+
currentActivity
.
getConfidence
());
boolean
wasMoving
=
isMoving
;
boolean
nowMoving
=
false
;
...
...
@@ -304,7 +330,7 @@ public class BackgroundGeolocationService extends Service implements GoogleApiCl
startTone
(
"long_beep"
);
// set our stationaryLocation
stationaryLocation
=
LocationServices
.
FusedLocationApi
.
getLastLocation
(
googleApiClient
);
EventBus
.
getDefault
().
post
(
new
BackgroundGeolocationService
.
StationaryLocation
(
stationaryLocation
));
EventBus
.
getDefault
().
post
(
new
StationaryLocation
(
stationaryLocation
));
}
}
}
...
...
@@ -436,6 +462,7 @@ public class BackgroundGeolocationService extends Service implements GoogleApiCl
}
private
void
requestLocationUpdates
()
{
if
(!
isPaused
||
!
isEnabled
)
{
return
;
}
// <-- Don't engage GPS when app is in foreground
LocationServices
.
FusedLocationApi
.
requestLocationUpdates
(
googleApiClient
,
locationRequest
,
locationUpdatePI
);
}
...
...
@@ -478,9 +505,7 @@ public class BackgroundGeolocationService extends Service implements GoogleApiCl
@Override
public
void
onDestroy
()
{
Log
.
w
(
TAG
,
"--------------------------------------"
);
Log
.
w
(
TAG
,
"- Destroy service"
);
Log
.
w
(
TAG
,
"--------------------------------------"
);
cleanUp
();
super
.
onDestroy
();
...
...
@@ -490,8 +515,7 @@ public class BackgroundGeolocationService extends Service implements GoogleApiCl
EventBus
.
getDefault
().
unregister
(
this
);
removeActivityUpdates
();
removeLocationUpdates
();
stopSelf
();
//wakeLock.release();
googleApiClient
.
disconnect
();
}
/**
...
...
@@ -516,6 +540,20 @@ public class BackgroundGeolocationService extends Service implements GoogleApiCl
}
}
public
static
class
PausedEvent
{
public
boolean
isPaused
;
public
PausedEvent
(
boolean
paused
)
{
isPaused
=
paused
;
}
}
public
static
class
PaceChangeEvent
{
public
boolean
isMoving
;
public
PaceChangeEvent
(
boolean
moving
)
{
isMoving
=
moving
;
}
}
class
StationaryLocation
extends
Location
{
public
StationaryLocation
(
Location
l
)
{
...
...
@@ -543,5 +581,4 @@ public class BackgroundGeolocationService extends Service implements GoogleApiCl
Log
.
d
(
TAG
,
"PostLocationTask#onPostExecture"
);
}
}
}
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