Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
cordova-plugin-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-plugin-background-geolocation
Commits
a940ddd8
Commit
a940ddd8
authored
Oct 15, 2013
by
Brian Samson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
plugin installs and is working with previous api
parent
c7d0d19c
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
57 additions
and
43 deletions
+57
-43
plugin.xml
plugin.xml
+12
-10
BackgroundGpsPlugin.java
src/android/BackgroundGpsPlugin.java
+3
-3
LocationUpdateService.java
src/android/LocationUpdateService.java
+17
-12
android-support-v4.jar
src/android/android-support-v4.jar
+0
-0
DAOFactory.java
src/android/data/DAOFactory.java
+6
-4
Location.java
src/android/data/Location.java
+1
-1
LocationDAO.java
src/android/data/LocationDAO.java
+1
-1
LocationOpenHelper.java
src/android/data/sqlite/LocationOpenHelper.java
+4
-6
SQLiteLocationDAO.java
src/android/data/sqlite/SQLiteLocationDAO.java
+13
-6
No files found.
plugin.xml
View file @
a940ddd8
...
@@ -18,16 +18,18 @@
...
@@ -18,16 +18,18 @@
<!-- android -->
<!-- android -->
<platform
name=
"android"
>
<platform
name=
"android"
>
<source-file
src=
"src/android/BackgroundGpsPlugin.java"
target-dir=
"src/com/tenforwardconsulting/cordova/b
ackgroundgeolocation
"
/>
<source-file
src=
"src/android/BackgroundGpsPlugin.java"
target-dir=
"src/com/tenforwardconsulting/cordova/b
gloc
"
/>
<source-file
src=
"src/android/LocationUpdateService.java"
target-dir=
"src/com/tenforwardconsulting/cordova/b
ackgroundgeolocation
"
/>
<source-file
src=
"src/android/LocationUpdateService.java"
target-dir=
"src/com/tenforwardconsulting/cordova/b
gloc
"
/>
<source-file
src=
"src/android/data/DAOFactory.java"
target-dir=
"src/com/tenforwardconsulting/cordova/b
ackgroundgeolocation
"
/>
<source-file
src=
"src/android/data/DAOFactory.java"
target-dir=
"src/com/tenforwardconsulting/cordova/b
gloc/data
"
/>
<source-file
src=
"src/android/data/Location.java"
target-dir=
"src/com/tenforwardconsulting/cordova/b
ackgroundgeolocation
"
/>
<source-file
src=
"src/android/data/Location.java"
target-dir=
"src/com/tenforwardconsulting/cordova/b
gloc/data
"
/>
<source-file
src=
"src/android/data/LocationDAO.java"
target-dir=
"src/com/tenforwardconsulting/cordova/b
ackgroundgeolocation
"
/>
<source-file
src=
"src/android/data/LocationDAO.java"
target-dir=
"src/com/tenforwardconsulting/cordova/b
gloc/data
"
/>
<source-file
src=
"src/android/data/sqlite/LocationOpenHelper.java"
target-dir=
"src/com/tenforwardconsulting/cordova/b
ackgroundgeolocation
"
/>
<source-file
src=
"src/android/data/sqlite/LocationOpenHelper.java"
target-dir=
"src/com/tenforwardconsulting/cordova/b
gloc/data/sqlite
"
/>
<source-file
src=
"src/android/data/sqlite/SQLiteLocationDAO.java"
target-dir=
"src/com/tenforwardconsulting/cordova/b
ackgroundgeolocation
"
/>
<source-file
src=
"src/android/data/sqlite/SQLiteLocationDAO.java"
target-dir=
"src/com/tenforwardconsulting/cordova/b
gloc/data/sqlite
"
/>
<config-file
target=
"AndroidManifest.xml"
parent=
"/manifest/application"
>
<source-file
src=
"src/android/android-support-v4.jar"
target-dir=
"libs"
/>
<service
android:enabled=
"true"
android:name=
"com.tenforwardconsulting.cordova.backgroundgeolocation.LocationUpdateService"
android:process=
":remote"
/>
<config-file
target=
"AndroidManifest.xml"
parent=
"/manifest/application"
>
<service
android:enabled=
"true"
android:name=
"com.tenforwardconsulting.cordova.bgloc.LocationUpdateService"
android:process=
":remote"
/>
</config-file>
</config-file>
<config-file
target=
"AndroidManifest.xml"
parent=
"/manifest"
>
<config-file
target=
"AndroidManifest.xml"
parent=
"/manifest"
>
...
@@ -38,7 +40,7 @@
...
@@ -38,7 +40,7 @@
</config-file>
</config-file>
<config-file
target=
"res/xml/config.xml"
parent=
"/*"
>
<config-file
target=
"res/xml/config.xml"
parent=
"/*"
>
<feature
name=
"BackgroundGeoLocation"
>
<feature
name=
"BackgroundGeoLocation"
>
<param
name=
"android-package"
value=
"com.tenforwardconsulting.cordova.b
ackground-geolocatio
n"
/>
<param
name=
"android-package"
value=
"com.tenforwardconsulting.cordova.b
gloc.BackgroundGpsPlugi
n"
/>
</feature>
</feature>
</config-file>
</config-file>
</platform>
</platform>
...
...
src/android/BackgroundGpsPlugin.java
View file @
a940ddd8
package
com
.
tenforwardconsulting
.
cordova
.
b
ackgroundgeolocation
;
package
com
.
tenforwardconsulting
.
cordova
.
b
gloc
;
import
org.apache.cordova.
api.
CallbackContext
;
import
org.apache.cordova.CallbackContext
;
import
org.apache.cordova.
api.
CordovaPlugin
;
import
org.apache.cordova.CordovaPlugin
;
import
org.json.JSONArray
;
import
org.json.JSONArray
;
import
org.json.JSONException
;
import
org.json.JSONException
;
...
...
src/android/LocationUpdateService.java
View file @
a940ddd8
package
com
.
tenforwardconsulting
.
cordova
.
b
ackgroundgeolocation
;
package
com
.
tenforwardconsulting
.
cordova
.
b
gloc
;
import
org.apache.http.HttpResponse
;
import
org.apache.http.HttpResponse
;
import
org.apache.http.client.methods.HttpPost
;
import
org.apache.http.client.methods.HttpPost
;
...
@@ -6,9 +6,10 @@ import org.apache.http.entity.StringEntity;
...
@@ -6,9 +6,10 @@ import org.apache.http.entity.StringEntity;
import
org.apache.http.impl.client.DefaultHttpClient
;
import
org.apache.http.impl.client.DefaultHttpClient
;
import
org.json.JSONObject
;
import
org.json.JSONObject
;
import
com.tenforwardconsulting.cordova.b
ackgroundgeolocation
.data.DAOFactory
;
import
com.tenforwardconsulting.cordova.b
gloc
.data.DAOFactory
;
import
com.tenforwardconsulting.cordova.b
ackgroundgeolocation
.data.LocationDAO
;
import
com.tenforwardconsulting.cordova.b
gloc
.data.LocationDAO
;
import
android.app.Application
;
import
android.app.Notification
;
import
android.app.Notification
;
import
android.app.NotificationManager
;
import
android.app.NotificationManager
;
import
android.support.v4.app.NotificationCompat
;
import
android.support.v4.app.NotificationCompat
;
...
@@ -110,11 +111,15 @@ public class LocationUpdateService extends Service implements LocationListener {
...
@@ -110,11 +111,15 @@ public class LocationUpdateService extends Service implements LocationListener {
PackageManager
pm
=
this
.
getPackageManager
();
PackageManager
pm
=
this
.
getPackageManager
();
Intent
notificationIntent
=
pm
.
getLaunchIntentForPackage
(
this
.
getPackageName
());
Intent
notificationIntent
=
pm
.
getLaunchIntentForPackage
(
this
.
getPackageName
());
notificationIntent
.
addFlags
(
Intent
.
FLAG_ACTIVITY_SINGLE_TOP
);
notificationIntent
.
addFlags
(
Intent
.
FLAG_ACTIVITY_SINGLE_TOP
);
Application
application
=
this
.
getApplication
();
int
backgroundIconId
=
application
.
getResources
().
getIdentifier
(
"background_notification"
,
"drawable"
,
application
.
getPackageName
());
int
appNameId
=
application
.
getResources
().
getIdentifier
(
"app_name"
,
"string"
,
application
.
getPackageName
());
PendingIntent
contentIntent
=
PendingIntent
.
getActivity
(
this
,
0
,
notificationIntent
,
0
);
PendingIntent
contentIntent
=
PendingIntent
.
getActivity
(
this
,
0
,
notificationIntent
,
0
);
NotificationCompat
.
Builder
builder
=
new
NotificationCompat
.
Builder
(
this
)
NotificationCompat
.
Builder
builder
=
new
NotificationCompat
.
Builder
(
this
)
.
setSmallIcon
(
R
.
drawable
.
notification
)
.
setSmallIcon
(
backgroundIconId
)
.
setContentTitle
(
this
.
getString
(
R
.
string
.
app_name
))
.
setContentTitle
(
this
.
getString
(
appNameId
))
.
setOngoing
(
true
)
.
setOngoing
(
true
)
.
setContentIntent
(
contentIntent
)
.
setContentIntent
(
contentIntent
)
.
setWhen
(
System
.
currentTimeMillis
());
.
setWhen
(
System
.
currentTimeMillis
());
...
@@ -164,7 +169,7 @@ public class LocationUpdateService extends Service implements LocationListener {
...
@@ -164,7 +169,7 @@ public class LocationUpdateService extends Service implements LocationListener {
Log
.
d
(
TAG
,
"afterexecute "
+
task
.
getStatus
());
Log
.
d
(
TAG
,
"afterexecute "
+
task
.
getStatus
());
}
}
private
boolean
postLocation
(
com
.
tenforwardconsulting
.
cordova
.
b
ackgroundgeolocation
.
data
.
Location
l
)
{
private
boolean
postLocation
(
com
.
tenforwardconsulting
.
cordova
.
b
gloc
.
data
.
Location
l
)
{
if
(
l
==
null
)
{
if
(
l
==
null
)
{
Log
.
w
(
TAG
,
"postLocation: null location"
);
Log
.
w
(
TAG
,
"postLocation: null location"
);
return
false
;
return
false
;
...
@@ -203,8 +208,8 @@ public class LocationUpdateService extends Service implements LocationListener {
...
@@ -203,8 +208,8 @@ public class LocationUpdateService extends Service implements LocationListener {
}
}
}
}
private
void
persistLocation
(
Location
location
)
{
private
void
persistLocation
(
Location
location
)
{
LocationDAO
dao
=
DAOFactory
.
createLocationDAO
();
LocationDAO
dao
=
DAOFactory
.
createLocationDAO
(
this
.
getApplicationContext
()
);
com
.
tenforwardconsulting
.
cordova
.
b
ackgroundgeolocation
.
data
.
Location
savedLocation
=
com
.
tenforwardconsulting
.
cordova
.
backgroundgeolocation
.
data
.
Location
.
fromAndroidLocation
(
location
);
com
.
tenforwardconsulting
.
cordova
.
b
gloc
.
data
.
Location
savedLocation
=
com
.
tenforwardconsulting
.
cordova
.
bgloc
.
data
.
Location
.
fromAndroidLocation
(
location
);
if
(
dao
.
persistLocation
(
savedLocation
))
{
if
(
dao
.
persistLocation
(
savedLocation
))
{
Log
.
d
(
TAG
,
"Persisted Location: "
+
savedLocation
);
Log
.
d
(
TAG
,
"Persisted Location: "
+
savedLocation
);
...
@@ -239,7 +244,7 @@ public class LocationUpdateService extends Service implements LocationListener {
...
@@ -239,7 +244,7 @@ public class LocationUpdateService extends Service implements LocationListener {
Log
.
d
(
TAG
,
"#timestamp "
+
System
.
currentTimeMillis
());
Log
.
d
(
TAG
,
"#timestamp "
+
System
.
currentTimeMillis
());
if
(
lastUpdateTime
+
5
*
60
*
1000
<
SystemClock
.
elapsedRealtime
())
{
if
(
lastUpdateTime
+
5
*
60
*
1000
<
SystemClock
.
elapsedRealtime
())
{
Log
.
d
(
TAG
,
"5 minutes, forcing update with last location"
);
Log
.
d
(
TAG
,
"5 minutes, forcing update with last location"
);
postLocation
(
com
.
tenforwardconsulting
.
cordova
.
b
ackgroundgeolocation
.
Location
.
fromAndroidLocation
(
postLocation
(
com
.
tenforwardconsulting
.
cordova
.
b
gloc
.
data
.
Location
.
fromAndroidLocation
(
locationManager
.
getLastKnownLocation
(
LocationManager
.
NETWORK_PROVIDER
)));
locationManager
.
getLastKnownLocation
(
LocationManager
.
NETWORK_PROVIDER
)));
}
}
try
{
try
{
...
@@ -258,8 +263,8 @@ public class LocationUpdateService extends Service implements LocationListener {
...
@@ -258,8 +263,8 @@ public class LocationUpdateService extends Service implements LocationListener {
@Override
@Override
protected
Boolean
doInBackground
(
Object
...
objects
)
{
protected
Boolean
doInBackground
(
Object
...
objects
)
{
Log
.
d
(
TAG
,
"Executing PostLocationTask#doInBackground"
);
Log
.
d
(
TAG
,
"Executing PostLocationTask#doInBackground"
);
LocationDAO
locationDAO
=
DAOFactory
.
createLocationDAO
();
LocationDAO
locationDAO
=
DAOFactory
.
createLocationDAO
(
LocationUpdateService
.
this
.
getApplicationContext
()
);
for
(
com
.
tenforwardconsulting
.
cordova
.
b
ackgroundgeolocation
.
data
.
Location
savedLocation
:
locationDAO
.
getAllLocations
())
{
for
(
com
.
tenforwardconsulting
.
cordova
.
b
gloc
.
data
.
Location
savedLocation
:
locationDAO
.
getAllLocations
())
{
Log
.
d
(
TAG
,
"Posting saved location"
);
Log
.
d
(
TAG
,
"Posting saved location"
);
if
(
postLocation
(
savedLocation
))
{
if
(
postLocation
(
savedLocation
))
{
locationDAO
.
deleteLocation
(
savedLocation
);
locationDAO
.
deleteLocation
(
savedLocation
);
...
...
src/android/android-support-v4.jar
0 → 100644
View file @
a940ddd8
File added
src/android/data/DAOFactory.java
View file @
a940ddd8
package
com
.
tenforwardconsulting
.
cordova
.
b
ackgroundgeolocation
.
data
;
package
com
.
tenforwardconsulting
.
cordova
.
b
gloc
.
data
;
import
com.tenforwardconsulting.cordova.backgroundgeolocation.data.sqlite.SQLiteLocationDAO
;
import
android.content.Context
;
import
com.tenforwardconsulting.cordova.bgloc.data.sqlite.SQLiteLocationDAO
;
public
abstract
class
DAOFactory
{
public
abstract
class
DAOFactory
{
public
static
LocationDAO
createLocationDAO
()
{
public
static
LocationDAO
createLocationDAO
(
Context
context
)
{
//Very basic for now
//Very basic for now
return
new
SQLiteLocationDAO
();
return
new
SQLiteLocationDAO
(
context
);
}
}
}
}
src/android/data/Location.java
View file @
a940ddd8
package
com
.
tenforwardconsulting
.
cordova
.
b
ackgroundgeolocation
.
data
;
package
com
.
tenforwardconsulting
.
cordova
.
b
gloc
.
data
;
import
java.util.Date
;
import
java.util.Date
;
...
...
src/android/data/LocationDAO.java
View file @
a940ddd8
package
com
.
tenforwardconsulting
.
cordova
.
b
ackgroundgeolocation
.
data
;
package
com
.
tenforwardconsulting
.
cordova
.
b
gloc
.
data
;
public
interface
LocationDAO
{
public
interface
LocationDAO
{
public
Location
[]
getAllLocations
();
public
Location
[]
getAllLocations
();
...
...
src/android/data/sqlite/LocationOpenHelper.java
View file @
a940ddd8
package
com
.
tenforwardconsulting
.
cordova
.
b
ackgroundgeolocation
;
package
com
.
tenforwardconsulting
.
cordova
.
b
gloc
.
data
.
sqlite
;
import
com.geocrowd.android.core.GeoCrowdApplication
;
import
android.content.Context
;
import
android.content.Context
;
import
android.database.sqlite.SQLiteDatabase
;
import
android.database.sqlite.SQLiteDatabase
;
import
android.database.sqlite.SQLiteOpenHelper
;
import
android.database.sqlite.SQLiteOpenHelper
;
import
android.util.Log
;
import
android.util.Log
;
public
class
LocationOpenHelper
extends
SQLiteOpenHelper
{
public
class
LocationOpenHelper
extends
SQLiteOpenHelper
{
private
static
final
String
SQLITE_DATABASE_NAME
=
"cordova_bg_locations"
;
private
static
final
int
DATABASE_VERSION
=
1
;
private
static
final
int
DATABASE_VERSION
=
1
;
public
static
final
String
LOCATION_TABLE_NAME
=
"location"
;
public
static
final
String
LOCATION_TABLE_NAME
=
"location"
;
private
static
final
String
LOCATION_TABLE_COLUMNS
=
private
static
final
String
LOCATION_TABLE_COLUMNS
=
...
@@ -23,8 +21,8 @@ public class LocationOpenHelper extends SQLiteOpenHelper {
...
@@ -23,8 +21,8 @@ public class LocationOpenHelper extends SQLiteOpenHelper {
");"
;
");"
;
LocationOpenHelper
(
Context
context
)
{
LocationOpenHelper
(
Context
context
)
{
super
(
context
,
GeoCrowdApplication
.
SQLITE_DATABASE_NAME
,
null
,
DATABASE_VERSION
);
super
(
context
,
SQLITE_DATABASE_NAME
,
null
,
DATABASE_VERSION
);
}
}
@Override
@Override
public
void
onCreate
(
SQLiteDatabase
db
)
{
public
void
onCreate
(
SQLiteDatabase
db
)
{
...
...
src/android/data/sqlite/SQLiteLocationDAO.java
View file @
a940ddd8
package
com
.
tenforwardconsulting
.
cordova
.
b
ackgroundgeolocation
.
data
.
sqlite
;
package
com
.
tenforwardconsulting
.
cordova
.
b
gloc
.
data
.
sqlite
;
import
java.text.ParseException
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.text.SimpleDateFormat
;
...
@@ -7,22 +7,29 @@ import java.util.Date;
...
@@ -7,22 +7,29 @@ import java.util.Date;
import
java.util.List
;
import
java.util.List
;
import
android.content.ContentValues
;
import
android.content.ContentValues
;
import
android.content.Context
;
import
android.database.Cursor
;
import
android.database.Cursor
;
import
android.database.sqlite.SQLiteDatabase
;
import
android.database.sqlite.SQLiteDatabase
;
import
android.util.Log
;
import
android.util.Log
;
import
com.tenforwardconsulting.cordova.b
ackgroundgeolocation
.data.Location
;
import
com.tenforwardconsulting.cordova.b
gloc
.data.Location
;
import
com.tenforwardconsulting.cordova.b
ackgroundgeolocation
.LocationDAO
;
import
com.tenforwardconsulting.cordova.b
gloc.data
.LocationDAO
;
public
class
SQLiteLocationDAO
implements
LocationDAO
{
public
class
SQLiteLocationDAO
implements
LocationDAO
{
public
static
final
String
DATE_FORMAT
=
"yyyy-MM-dd HH:mm:ss"
;
public
static
final
String
DATE_FORMAT
=
"yyyy-MM-dd HH:mm:ss"
;
private
static
final
String
TAG
=
"SQLiteLocationDAO"
;
private
static
final
String
TAG
=
"SQLiteLocationDAO"
;
private
Context
context
;
public
SQLiteLocationDAO
(
Context
context
)
{
this
.
context
=
context
;
}
public
Location
[]
getAllLocations
()
{
public
Location
[]
getAllLocations
()
{
SQLiteDatabase
db
=
null
;
SQLiteDatabase
db
=
null
;
Cursor
c
=
null
;
Cursor
c
=
null
;
List
<
Location
>
all
=
new
ArrayList
<
Location
>();
List
<
Location
>
all
=
new
ArrayList
<
Location
>();
try
{
try
{
db
=
new
LocationOpenHelper
(
GeoCrowdApplication
.
getApplication
().
getApplicationContext
()
).
getReadableDatabase
();
db
=
new
LocationOpenHelper
(
context
).
getReadableDatabase
();
c
=
db
.
query
(
LocationOpenHelper
.
LOCATION_TABLE_NAME
,
null
,
null
,
null
,
null
,
null
,
null
);
c
=
db
.
query
(
LocationOpenHelper
.
LOCATION_TABLE_NAME
,
null
,
null
,
null
,
null
,
null
,
null
);
while
(
c
.
moveToNext
())
{
while
(
c
.
moveToNext
())
{
all
.
add
(
hydrate
(
c
));
all
.
add
(
hydrate
(
c
));
...
@@ -39,7 +46,7 @@ public class SQLiteLocationDAO implements LocationDAO {
...
@@ -39,7 +46,7 @@ public class SQLiteLocationDAO implements LocationDAO {
}
}
public
boolean
persistLocation
(
Location
location
)
{
public
boolean
persistLocation
(
Location
location
)
{
SQLiteDatabase
db
=
new
LocationOpenHelper
(
GeoCrowdApplication
.
getApplication
().
getApplicationContext
()
).
getWritableDatabase
();
SQLiteDatabase
db
=
new
LocationOpenHelper
(
context
).
getWritableDatabase
();
db
.
beginTransaction
();
db
.
beginTransaction
();
ContentValues
values
=
getContentValues
(
location
);
ContentValues
values
=
getContentValues
(
location
);
long
rowId
=
db
.
insert
(
LocationOpenHelper
.
LOCATION_TABLE_NAME
,
null
,
values
);
long
rowId
=
db
.
insert
(
LocationOpenHelper
.
LOCATION_TABLE_NAME
,
null
,
values
);
...
@@ -57,7 +64,7 @@ public class SQLiteLocationDAO implements LocationDAO {
...
@@ -57,7 +64,7 @@ public class SQLiteLocationDAO implements LocationDAO {
}
}
public
void
deleteLocation
(
Location
location
)
{
public
void
deleteLocation
(
Location
location
)
{
SQLiteDatabase
db
=
new
LocationOpenHelper
(
GeoCrowdApplication
.
getApplication
().
getApplicationContext
()
).
getWritableDatabase
();
SQLiteDatabase
db
=
new
LocationOpenHelper
(
context
).
getWritableDatabase
();
db
.
beginTransaction
();
db
.
beginTransaction
();
db
.
delete
(
LocationOpenHelper
.
LOCATION_TABLE_NAME
,
"id = ?"
,
new
String
[]{
location
.
getId
().
toString
()});
db
.
delete
(
LocationOpenHelper
.
LOCATION_TABLE_NAME
,
"id = ?"
,
new
String
[]{
location
.
getId
().
toString
()});
db
.
setTransactionSuccessful
();
db
.
setTransactionSuccessful
();
...
...
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