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
Show 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 = {
...
@@ -172,23 +172,28 @@ var app = {
// BackgroundGeoLocation is highly configurable.
// BackgroundGeoLocation is highly configurable.
bgGeo
.
configure
(
callbackFn
,
failureFn
,
{
bgGeo
.
configure
(
callbackFn
,
failureFn
,
{
debug
:
true
,
// <-- enable this hear sounds for background-geolocation life-cycle.
desiredAccuracy
:
0
,
desiredAccuracy
:
0
,
stationaryRadius
:
50
,
stationaryRadius
:
50
,
distanceFilter
:
50
,
distanceFilter
:
50
,
locationUpdateInterval
:
5000
,
locationUpdateInterval
:
5000
,
activityRecognitionInterval
:
10000
,
activityRecognitionInterval
:
10000
,
stopTimeout
:
1
,
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: {
headers: {
"X-FOO": "bar"
"X-FOO": "bar"
},
},
params: {
params: {
"
auth_token
"
:
"
bar
"
"auth_token": "maybe_your_server_authenticates_via_token_YES?"
},
}
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
});
});
// Turn ON the background-geolocation system. The user will be tracked whenever they suspend the app.
// 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 @@
...
@@ -30,7 +30,7 @@
<source-file
src=
"src/android/ActivityRecognitionService.java"
target-dir=
"src/com/transistorsoft/cordova/bggeo"
/>
<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"
/>
<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/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/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" />
<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 {
...
@@ -24,7 +24,7 @@ public class ActivityRecognitionService extends IntentService {
ActivityRecognitionResult
result
=
ActivityRecognitionResult
.
extractResult
(
intent
);
ActivityRecognitionResult
result
=
ActivityRecognitionResult
.
extractResult
(
intent
);
DetectedActivity
probableActivity
=
result
.
getMostProbableActivity
();
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
)
{
if
(
probableActivity
.
getConfidence
()
<
80
)
{
return
;
return
;
}
}
...
...
src/android/BackgroundGeolocationPlugin.java
View file @
1707abbd
...
@@ -8,6 +8,8 @@ import org.json.JSONArray;
...
@@ -8,6 +8,8 @@ import org.json.JSONArray;
import
org.json.JSONObject
;
import
org.json.JSONObject
;
import
org.json.JSONException
;
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
com.transistorsoft.cordova.bggeo.BackgroundGeolocationService.StationaryLocation
;
import
de.greenrobot.event.EventBus
;
import
de.greenrobot.event.EventBus
;
...
@@ -39,8 +41,6 @@ public class BackgroundGeolocationPlugin extends CordovaPlugin {
...
@@ -39,8 +41,6 @@ public class BackgroundGeolocationPlugin extends CordovaPlugin {
// Called when DetectedActivity is STILL
// Called when DetectedActivity is STILL
private
CallbackContext
stationaryCallback
;
private
CallbackContext
stationaryCallback
;
private
Location
stationaryLocation
;
public
static
boolean
isActive
()
{
public
static
boolean
isActive
()
{
return
gWebView
!=
null
;
return
gWebView
!=
null
;
}
}
...
@@ -79,10 +79,13 @@ public class BackgroundGeolocationPlugin extends CordovaPlugin {
...
@@ -79,10 +79,13 @@ public class BackgroundGeolocationPlugin extends CordovaPlugin {
}
}
}
else
if
(
ACTION_ON_PACE_CHANGE
.
equalsIgnoreCase
(
action
))
{
}
else
if
(
ACTION_ON_PACE_CHANGE
.
equalsIgnoreCase
(
action
))
{
if
(!
isEnabled
)
{
if
(!
isEnabled
)
{
Log
.
w
(
TAG
,
"- Cannot change pace while
in #stop mode
"
);
Log
.
w
(
TAG
,
"- Cannot change pace while
disabled
"
);
result
=
false
;
result
=
false
;
callbackContext
.
error
(
"Cannot #changePace while
in #stop mode
"
);
callbackContext
.
error
(
"Cannot #changePace while
disabled
"
);
}
else
{
}
else
{
PaceChangeEvent
event
=
new
PaceChangeEvent
(
data
.
getBoolean
(
0
));
EventBus
.
getDefault
().
post
(
event
);
result
=
true
;
result
=
true
;
callbackContext
.
success
();
callbackContext
.
success
();
}
}
...
@@ -157,12 +160,13 @@ public class BackgroundGeolocationPlugin extends CordovaPlugin {
...
@@ -157,12 +160,13 @@ public class BackgroundGeolocationPlugin extends CordovaPlugin {
Log
.
i
(
TAG
,
"- onPause"
);
Log
.
i
(
TAG
,
"- onPause"
);
if
(
isEnabled
)
{
if
(
isEnabled
)
{
//setPace(isMoving);
//setPace(isMoving);
EventBus
.
getDefault
().
post
(
new
PausedEvent
(
true
));
}
}
}
}
public
void
onResume
(
boolean
multitasking
)
{
public
void
onResume
(
boolean
multitasking
)
{
Log
.
i
(
TAG
,
"- onResume"
);
Log
.
i
(
TAG
,
"- onResume"
);
if
(
isEnabled
)
{
if
(
isEnabled
)
{
//removeLocationUpdates(
);
EventBus
.
getDefault
().
post
(
new
PausedEvent
(
false
)
);
}
}
}
}
...
@@ -175,7 +179,6 @@ public class BackgroundGeolocationPlugin extends CordovaPlugin {
...
@@ -175,7 +179,6 @@ public class BackgroundGeolocationPlugin extends CordovaPlugin {
result
.
setKeepCallback
(
true
);
result
.
setKeepCallback
(
true
);
if
(
location
instanceof
StationaryLocation
)
{
if
(
location
instanceof
StationaryLocation
)
{
stationaryLocation
=
location
;
if
(
stationaryCallback
!=
null
)
{
if
(
stationaryCallback
!=
null
)
{
runInBackground
(
stationaryCallback
,
result
);
runInBackground
(
stationaryCallback
,
result
);
}
}
...
...
src/android/BackgroundGeolocationService.java
View file @
1707abbd
...
@@ -35,8 +35,6 @@ import android.os.AsyncTask;
...
@@ -35,8 +35,6 @@ import android.os.AsyncTask;
import
android.os.Build
;
import
android.os.Build
;
import
android.os.Bundle
;
import
android.os.Bundle
;
import
android.os.IBinder
;
import
android.os.IBinder
;
import
android.os.PowerManager
;
import
android.os.PowerManager.WakeLock
;
import
android.util.Log
;
import
android.util.Log
;
public
class
BackgroundGeolocationService
extends
Service
implements
GoogleApiClient
.
ConnectionCallbacks
,
GoogleApiClient
.
OnConnectionFailedListener
{
public
class
BackgroundGeolocationService
extends
Service
implements
GoogleApiClient
.
ConnectionCallbacks
,
GoogleApiClient
.
OnConnectionFailedListener
{
...
@@ -49,7 +47,6 @@ public class BackgroundGeolocationService extends Service implements GoogleApiCl
...
@@ -49,7 +47,6 @@ public class BackgroundGeolocationService extends Service implements GoogleApiCl
}
}
private
GoogleApiClient
googleApiClient
;
private
GoogleApiClient
googleApiClient
;
private
WakeLock
wakeLock
;
private
ToneGenerator
toneGenerator
;
private
ToneGenerator
toneGenerator
;
private
PendingIntent
activityRecognitionPI
;
private
PendingIntent
activityRecognitionPI
;
...
@@ -109,6 +106,8 @@ public class BackgroundGeolocationService extends Service implements GoogleApiCl
...
@@ -109,6 +106,8 @@ public class BackgroundGeolocationService extends Service implements GoogleApiCl
// Flags
// Flags
private
Boolean
isEnabled
=
false
;
private
Boolean
isEnabled
=
false
;
private
Boolean
isMoving
=
false
;
private
Boolean
isMoving
=
false
;
private
Boolean
isPaused
=
true
;
private
long
stoppedAt
=
0
;
private
long
stoppedAt
=
0
;
private
Location
stationaryLocation
;
private
Location
stationaryLocation
;
...
@@ -116,7 +115,6 @@ public class BackgroundGeolocationService extends Service implements GoogleApiCl
...
@@ -116,7 +115,6 @@ public class BackgroundGeolocationService extends Service implements GoogleApiCl
@Override
@Override
public
int
onStartCommand
(
Intent
intent
,
int
flags
,
int
startId
)
{
public
int
onStartCommand
(
Intent
intent
,
int
flags
,
int
startId
)
{
Log
.
i
(
TAG
,
"- Start BackgroundGeolocationService"
);
instance
=
this
;
instance
=
this
;
EventBus
.
getDefault
().
register
(
this
);
EventBus
.
getDefault
().
register
(
this
);
...
@@ -127,7 +125,7 @@ public class BackgroundGeolocationService extends Service implements GoogleApiCl
...
@@ -127,7 +125,7 @@ public class BackgroundGeolocationService extends Service implements GoogleApiCl
distanceFilter
=
intent
.
getFloatExtra
(
"distanceFilter"
,
50
);
distanceFilter
=
intent
.
getFloatExtra
(
"distanceFilter"
,
50
);
desiredAccuracy
=
intent
.
getIntExtra
(
"desiredAccuracy"
,
10
);
desiredAccuracy
=
intent
.
getIntExtra
(
"desiredAccuracy"
,
10
);
locationUpdateInterval
=
intent
.
getIntExtra
(
"locationUpdateInterval"
,
30000
);
locationUpdateInterval
=
intent
.
getIntExtra
(
"locationUpdateInterval"
,
30000
);
activityRecognitionInterval
=
intent
.
getIntExtra
(
"activityRecognitionInterval"
,
1
0000
);
activityRecognitionInterval
=
intent
.
getIntExtra
(
"activityRecognitionInterval"
,
6
0000
);
stopTimeout
=
intent
.
getLongExtra
(
"stopTimeout"
,
0
);
stopTimeout
=
intent
.
getLongExtra
(
"stopTimeout"
,
0
);
forceReload
=
intent
.
getBooleanExtra
(
"forceReload"
,
false
);
forceReload
=
intent
.
getBooleanExtra
(
"forceReload"
,
false
);
...
@@ -144,6 +142,17 @@ public class BackgroundGeolocationService extends Service implements GoogleApiCl
...
@@ -144,6 +142,17 @@ public class BackgroundGeolocationService extends Service implements GoogleApiCl
e
.
printStackTrace
();
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.
// For debug sounds, turn on ToneGenerator.
if
(
isDebugging
)
{
if
(
isDebugging
)
{
toneGenerator
=
new
ToneGenerator
(
AudioManager
.
STREAM_NOTIFICATION
,
100
);
toneGenerator
=
new
ToneGenerator
(
AudioManager
.
STREAM_NOTIFICATION
,
100
);
...
@@ -172,12 +181,6 @@ public class BackgroundGeolocationService extends Service implements GoogleApiCl
...
@@ -172,12 +181,6 @@ public class BackgroundGeolocationService extends Service implements GoogleApiCl
Log
.
e
(
TAG
,
"- GooglePlayServices unavailable"
);
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
;
return
Service
.
START_REDELIVER_INTENT
;
}
}
...
@@ -208,6 +211,29 @@ public class BackgroundGeolocationService extends Service implements GoogleApiCl
...
@@ -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
* EventBus listener for ARS
* @param {ActivityRecognitionResult} result
* @param {ActivityRecognitionResult} result
...
@@ -215,7 +241,7 @@ public class BackgroundGeolocationService extends Service implements GoogleApiCl
...
@@ -215,7 +241,7 @@ public class BackgroundGeolocationService extends Service implements GoogleApiCl
public
void
onEventMainThread
(
ActivityRecognitionResult
result
)
{
public
void
onEventMainThread
(
ActivityRecognitionResult
result
)
{
currentActivity
=
result
.
getMostProbableActivity
();
currentActivity
=
result
.
getMostProbableActivity
();
String
probableActivityName
=
getActivityName
(
currentActivity
.
getType
());
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
wasMoving
=
isMoving
;
boolean
nowMoving
=
false
;
boolean
nowMoving
=
false
;
...
@@ -304,7 +330,7 @@ public class BackgroundGeolocationService extends Service implements GoogleApiCl
...
@@ -304,7 +330,7 @@ public class BackgroundGeolocationService extends Service implements GoogleApiCl
startTone
(
"long_beep"
);
startTone
(
"long_beep"
);
// set our stationaryLocation
// set our stationaryLocation
stationaryLocation
=
LocationServices
.
FusedLocationApi
.
getLastLocation
(
googleApiClient
);
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
...
@@ -436,6 +462,7 @@ public class BackgroundGeolocationService extends Service implements GoogleApiCl
}
}
private
void
requestLocationUpdates
()
{
private
void
requestLocationUpdates
()
{
if
(!
isPaused
||
!
isEnabled
)
{
return
;
}
// <-- Don't engage GPS when app is in foreground
LocationServices
.
FusedLocationApi
.
requestLocationUpdates
(
googleApiClient
,
locationRequest
,
locationUpdatePI
);
LocationServices
.
FusedLocationApi
.
requestLocationUpdates
(
googleApiClient
,
locationRequest
,
locationUpdatePI
);
}
}
...
@@ -478,9 +505,7 @@ public class BackgroundGeolocationService extends Service implements GoogleApiCl
...
@@ -478,9 +505,7 @@ public class BackgroundGeolocationService extends Service implements GoogleApiCl
@Override
@Override
public
void
onDestroy
()
{
public
void
onDestroy
()
{
Log
.
w
(
TAG
,
"--------------------------------------"
);
Log
.
w
(
TAG
,
"- Destroy service"
);
Log
.
w
(
TAG
,
"- Destroy service"
);
Log
.
w
(
TAG
,
"--------------------------------------"
);
cleanUp
();
cleanUp
();
super
.
onDestroy
();
super
.
onDestroy
();
...
@@ -490,8 +515,7 @@ public class BackgroundGeolocationService extends Service implements GoogleApiCl
...
@@ -490,8 +515,7 @@ public class BackgroundGeolocationService extends Service implements GoogleApiCl
EventBus
.
getDefault
().
unregister
(
this
);
EventBus
.
getDefault
().
unregister
(
this
);
removeActivityUpdates
();
removeActivityUpdates
();
removeLocationUpdates
();
removeLocationUpdates
();
stopSelf
();
googleApiClient
.
disconnect
();
//wakeLock.release();
}
}
/**
/**
...
@@ -516,6 +540,20 @@ public class BackgroundGeolocationService extends Service implements GoogleApiCl
...
@@ -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
{
class
StationaryLocation
extends
Location
{
public
StationaryLocation
(
Location
l
)
{
public
StationaryLocation
(
Location
l
)
{
...
@@ -543,5 +581,4 @@ public class BackgroundGeolocationService extends Service implements GoogleApiCl
...
@@ -543,5 +581,4 @@ public class BackgroundGeolocationService extends Service implements GoogleApiCl
Log
.
d
(
TAG
,
"PostLocationTask#onPostExecture"
);
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