Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
cordova-plugin-local-notifications
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nabil Sadki
cordova-plugin-local-notifications
Commits
4068dc38
Commit
4068dc38
authored
Nov 26, 2017
by
Sebastián Katzer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support for infinite trigger on Android
parent
c65e9473
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
36 additions
and
11 deletions
+36
-11
TriggerReceiver.java
src/android/TriggerReceiver.java
+8
-4
Notification.java
src/android/notification/Notification.java
+18
-6
Options.java
src/android/notification/Options.java
+9
-0
Request.java
src/android/notification/Request.java
+1
-1
No files found.
src/android/TriggerReceiver.java
View file @
4068dc38
...
...
@@ -22,7 +22,6 @@
package
de
.
appplant
.
cordova
.
plugin
.
localnotification
;
import
android.content.Context
;
import
android.os.Build
;
import
android.os.Bundle
;
import
android.os.PowerManager
;
...
...
@@ -30,12 +29,12 @@ import de.appplant.cordova.plugin.notification.Builder;
import
de.appplant.cordova.plugin.notification.Manager
;
import
de.appplant.cordova.plugin.notification.Notification
;
import
de.appplant.cordova.plugin.notification.Options
;
import
de.appplant.cordova.plugin.notification.Request
;
import
de.appplant.cordova.plugin.notification.receiver.AbstractTriggerReceiver
;
import
static
android
.
content
.
Context
.
POWER_SERVICE
;
import
static
android
.
os
.
Build
.
VERSION
.
SDK_INT
;
import
static
android
.
os
.
Build
.
VERSION_CODES
.
LOLLIPOP
;
import
static
android
.
os
.
PowerManager
.
RELEASE_FLAG_WAIT_FOR_NO_PROXIMITY
;
/**
* The alarm receiver is triggered when a scheduled alarm is fired. This class
...
...
@@ -57,10 +56,11 @@ public class TriggerReceiver extends AbstractTriggerReceiver {
boolean
isUpdate
=
bundle
.
getBoolean
(
Notification
.
EXTRA_UPDATE
,
false
);
Context
context
=
notification
.
getContext
();
Options
options
=
notification
.
getOptions
();
Manager
manager
=
Manager
.
getInstance
(
context
);
int
badge
=
options
.
getBadgeNumber
();
if
(
badge
>
0
)
{
Manager
.
getInstance
(
context
)
.
setBadge
(
badge
);
manager
.
setBadge
(
badge
);
}
if
(
options
.
shallWakeUp
())
{
...
...
@@ -69,6 +69,10 @@ public class TriggerReceiver extends AbstractTriggerReceiver {
notification
.
show
();
if
(
options
.
isInfiniteTrigger
())
{
manager
.
schedule
(
new
Request
(
options
),
this
.
getClass
());
}
if
(!
isUpdate
)
{
LocalNotification
.
fireEvent
(
"trigger"
,
notification
);
}
...
...
@@ -95,7 +99,7 @@ public class TriggerReceiver extends AbstractTriggerReceiver {
wakeLock
.
acquire
(
1000
);
if
(
SDK_INT
>=
LOLLIPOP
)
{
wakeLock
.
release
(
RELEASE_FLAG_WAIT_FOR_NO_PROXIMITY
);
wakeLock
.
release
(
PowerManager
.
RELEASE_FLAG_WAIT_FOR_NO_PROXIMITY
);
}
else
{
wakeLock
.
release
();
}
...
...
src/android/notification/Notification.java
View file @
4068dc38
...
...
@@ -139,7 +139,7 @@ public final class Notification {
/**
* Notification type can be one of triggered or scheduled.
*/
public
Type
getType
()
{
public
Type
getType
()
{
Manager
mgr
=
Manager
.
getInstance
(
context
);
StatusBarNotification
[]
toasts
=
mgr
.
getActiveNotifications
();
int
id
=
getId
();
...
...
@@ -164,6 +164,8 @@ public final class Notification {
Set
<
String
>
ids
=
new
ArraySet
<
String
>();
AlarmManager
mgr
=
getAlarmMgr
();
cancelScheduledAlarms
();
do
{
Date
date
=
request
.
getTriggerDate
();
...
...
@@ -180,13 +182,17 @@ public final class Notification {
}
while
(
request
.
moveNext
());
if
(
intents
.
isEmpty
())
if
(
intents
.
isEmpty
())
{
unpersist
();
return
;
}
persist
(
ids
);
if
(!
options
.
isInfiniteTrigger
())
{
Intent
last
=
intents
.
get
(
intents
.
size
()
-
1
).
second
;
last
.
putExtra
(
Request
.
EXTRA_LAST
,
true
);
}
for
(
Pair
<
Date
,
Intent
>
pair
:
intents
)
{
Date
date
=
pair
.
first
;
...
...
@@ -257,20 +263,26 @@ public final class Notification {
/**
* Cancel the local notification.
*/
public
void
cancel
()
{
cancelScheduledAlarms
();
unpersist
();
getNotMgr
().
cancel
(
options
.
getId
());
}
/**
* Cancel the scheduled future local notification.
*
* Create an intent that looks similar, to the one that was registered
* using schedule. Making sure the notification id in the action is the
* same. Now we can search for such an intent using the 'getService'
* method and cancel it.
*/
p
ublic
void
cancel
()
{
p
rivate
void
cancelScheduledAlarms
()
{
SharedPreferences
prefs
=
getPrefs
(
PREF_KEY_PID
);
String
id
=
options
.
getIdentifier
();
Set
<
String
>
actions
=
prefs
.
getStringSet
(
id
,
null
);
unpersist
();
getNotMgr
().
cancel
(
options
.
getId
());
if
(
actions
==
null
)
return
;
...
...
src/android/notification/Options.java
View file @
4068dc38
...
...
@@ -528,6 +528,15 @@ public final class Options {
}
/**
* If the trigger shall be infinite.
*/
public
boolean
isInfiniteTrigger
()
{
JSONObject
trigger
=
options
.
optJSONObject
(
"trigger"
);
return
trigger
.
has
(
"every"
)
&&
trigger
.
optInt
(
"count"
,
-
1
)
<
0
;
}
/**
* The summary for inbox style notifications.
*/
String
getSummary
()
{
...
...
src/android/notification/Request.java
View file @
4068dc38
...
...
@@ -71,7 +71,7 @@ public final class Request {
public
Request
(
Options
options
)
{
this
.
options
=
options
;
this
.
spec
=
options
.
getTrigger
();
this
.
count
=
spec
.
optInt
(
"count"
,
1
);
this
.
count
=
Math
.
max
(
spec
.
optInt
(
"count"
)
,
1
);
this
.
trigger
=
buildTrigger
();
this
.
triggerDate
=
trigger
.
getNextTriggerDate
(
getBaseDate
());
}
...
...
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