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
23b7ebbc
Commit
23b7ebbc
authored
Mar 18, 2014
by
Chris Scott
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Take care with creating foreground Notification for pre API level 16
parent
5ba2132f
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
14 deletions
+32
-14
LocationUpdateService.java
src/android/LocationUpdateService.java
+32
-14
No files found.
src/android/LocationUpdateService.java
View file @
23b7ebbc
...
@@ -11,41 +11,45 @@ import org.json.JSONObject;
...
@@ -11,41 +11,45 @@ import org.json.JSONObject;
import
com.tenforwardconsulting.cordova.bgloc.data.DAOFactory
;
import
com.tenforwardconsulting.cordova.bgloc.data.DAOFactory
;
import
com.tenforwardconsulting.cordova.bgloc.data.LocationDAO
;
import
com.tenforwardconsulting.cordova.bgloc.data.LocationDAO
;
import
android.annotation.SuppressLint
;
import
android.annotation.TargetApi
;
import
android.annotation.TargetApi
;
import
android.app.AlarmManager
;
import
android.media.AudioManager
;
import
android.media.AudioManager
;
import
android.media.ToneGenerator
;
import
android.media.ToneGenerator
;
import
android.telephony.PhoneStateListener
;
import
android.telephony.PhoneStateListener
;
import
android.telephony.TelephonyManager
;
import
android.telephony.TelephonyManager
;
import
static
android
.
telephony
.
PhoneStateListener
.*;
import
android.telephony.CellLocation
;
import
android.telephony.CellLocation
;
import
android.app.AlarmManager
;
import
android.app.NotificationManager
;
import
android.app.NotificationManager
;
import
android.app.Notification
;
import
android.app.Notification
;
import
android.app.PendingIntent
;
import
android.app.PendingIntent
;
import
android.app.Service
;
import
android.app.Service
;
import
android.content.Context
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.content.Intent
;
import
android.content.IntentFilter
;
import
android.content.IntentFilter
;
import
android.content.BroadcastReceiver
;
import
android.content.BroadcastReceiver
;
import
android.location.Location
;
import
android.location.Location
;
import
android.location.Criteria
;
import
android.location.Criteria
;
import
android.location.LocationListener
;
import
android.location.LocationListener
;
import
android.location.LocationManager
;
import
android.location.LocationManager
;
import
android.net.ConnectivityManager
;
import
android.net.ConnectivityManager
;
import
android.net.NetworkInfo
;
import
android.net.NetworkInfo
;
import
android.os.AsyncTask
;
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
;
import
android.os.SystemClock
;
import
android.os.SystemClock
;
import
android.util.Log
;
import
android.util.Log
;
import
android.widget.Toast
;
import
android.widget.Toast
;
import
static
android
.
telephony
.
PhoneStateListener
.*;
import
static
java
.
lang
.
Math
.*;
import
static
java
.
lang
.
Math
.*;
public
class
LocationUpdateService
extends
Service
implements
LocationListener
{
public
class
LocationUpdateService
extends
Service
implements
LocationListener
{
...
@@ -162,15 +166,18 @@ public class LocationUpdateService extends Service implements LocationListener {
...
@@ -162,15 +166,18 @@ public class LocationUpdateService extends Service implements LocationListener {
main
.
setFlags
(
Intent
.
FLAG_ACTIVITY_CLEAR_TOP
|
Intent
.
FLAG_ACTIVITY_SINGLE_TOP
);
main
.
setFlags
(
Intent
.
FLAG_ACTIVITY_CLEAR_TOP
|
Intent
.
FLAG_ACTIVITY_SINGLE_TOP
);
PendingIntent
pendingIntent
=
PendingIntent
.
getActivity
(
this
,
0
,
main
,
PendingIntent
.
FLAG_UPDATE_CURRENT
);
PendingIntent
pendingIntent
=
PendingIntent
.
getActivity
(
this
,
0
,
main
,
PendingIntent
.
FLAG_UPDATE_CURRENT
);
Notification
notification
=
new
Notification
.
Builder
(
this
)
Notification
.
Builder
builder
=
new
Notification
.
Builder
(
this
);
.
setContentTitle
(
"Tracking ON"
)
builder
.
setContentTitle
(
"Background tracking"
);
.
setContentText
(
"Content Text"
)
builder
.
setContentText
(
"ENABLED"
);
.
setSmallIcon
(
android
.
R
.
drawable
.
ic_menu_mylocation
)
builder
.
setSmallIcon
(
android
.
R
.
drawable
.
ic_menu_mylocation
);
.
setContentIntent
(
pendingIntent
)
builder
.
setContentIntent
(
pendingIntent
);
.
build
();
Notification
notification
;
if
(
android
.
os
.
Build
.
VERSION
.
SDK_INT
>=
16
)
{
notification
=
buildForegroundNotification
(
builder
);
}
else
{
notification
=
buildForegroundNotificationCompat
(
builder
);
}
notification
.
flags
|=
Notification
.
FLAG_ONGOING_EVENT
|
Notification
.
FLAG_FOREGROUND_SERVICE
|
Notification
.
FLAG_NO_CLEAR
;
notification
.
flags
|=
Notification
.
FLAG_ONGOING_EVENT
|
Notification
.
FLAG_FOREGROUND_SERVICE
|
Notification
.
FLAG_NO_CLEAR
;
startForeground
(
startId
,
notification
);
startForeground
(
startId
,
notification
);
}
}
Log
.
i
(
TAG
,
"- url: "
+
url
);
Log
.
i
(
TAG
,
"- url: "
+
url
);
...
@@ -187,6 +194,17 @@ public class LocationUpdateService extends Service implements LocationListener {
...
@@ -187,6 +194,17 @@ public class LocationUpdateService extends Service implements LocationListener {
return
START_REDELIVER_INTENT
;
return
START_REDELIVER_INTENT
;
}
}
@TargetApi
(
16
)
private
Notification
buildForegroundNotification
(
Notification
.
Builder
builder
)
{
return
builder
.
build
();
}
@SuppressWarnings
(
"deprecation"
)
@TargetApi
(
15
)
private
Notification
buildForegroundNotificationCompat
(
Notification
.
Builder
builder
)
{
return
builder
.
getNotification
();
}
@Override
@Override
public
boolean
stopService
(
Intent
intent
)
{
public
boolean
stopService
(
Intent
intent
)
{
Log
.
i
(
TAG
,
"- Received stop: "
+
intent
);
Log
.
i
(
TAG
,
"- Received stop: "
+
intent
);
...
...
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