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
c967ea57
Commit
c967ea57
authored
Oct 24, 2017
by
Sebastián Katzer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add back all querry methods on Android
parent
be881a56
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
56 additions
and
74 deletions
+56
-74
LocalNotification.java
src/android/LocalNotification.java
+0
-0
Builder.java
src/android/notification/Builder.java
+13
-5
Manager.java
src/android/notification/Manager.java
+0
-0
Notification.java
src/android/notification/Notification.java
+42
-68
Options.java
src/android/notification/Options.java
+1
-1
No files found.
src/android/LocalNotification.java
View file @
c967ea57
This diff is collapsed.
Click to expand it.
src/android/notification/Builder.java
View file @
c967ea57
...
...
@@ -35,6 +35,9 @@ import java.util.Random;
import
de.appplant.cordova.plugin.notification.action.Action
;
import
static
android
.
app
.
PendingIntent
.
FLAG_CANCEL_CURRENT
;
import
static
android
.
app
.
PendingIntent
.
FLAG_UPDATE_CURRENT
;
/**
* Builder class for local notifications. Build fully configured local
* notification specified by JSON object passed from JS side.
...
...
@@ -47,6 +50,9 @@ public final class Builder {
// Notification options passed by JS
private
final
Options
options
;
// To generate unique request codes
private
final
Random
random
=
new
Random
();
// Receiver to handle the clear event
private
Class
<?>
clearReceiver
;
...
...
@@ -283,8 +289,10 @@ public final class Builder {
.
setAction
(
options
.
getIdentifier
())
.
putExtra
(
Notification
.
EXTRA_ID
,
options
.
getId
());
int
reqCode
=
random
.
nextInt
();
PendingIntent
deleteIntent
=
PendingIntent
.
getBroadcast
(
context
,
0
,
intent
,
PendingIntent
.
FLAG_UPDATE_CURRENT
);
context
,
reqCode
,
intent
,
FLAG_UPDATE_CURRENT
);
builder
.
setDeleteIntent
(
deleteIntent
);
}
...
...
@@ -307,10 +315,10 @@ public final class Builder {
.
putExtra
(
Options
.
EXTRA_LAUNCH
,
options
.
isLaunchingApp
())
.
setFlags
(
Intent
.
FLAG_ACTIVITY_NO_HISTORY
);
int
reqCode
=
new
Random
()
.
nextInt
();
int
reqCode
=
random
.
nextInt
();
PendingIntent
contentIntent
=
PendingIntent
.
getActivity
(
context
,
reqCode
,
intent
,
PendingIntent
.
FLAG_UPDATE_CURRENT
);
context
,
reqCode
,
intent
,
FLAG_UPDATE_CURRENT
);
builder
.
setContentIntent
(
contentIntent
);
}
...
...
@@ -354,10 +362,10 @@ public final class Builder {
.
putExtra
(
Options
.
EXTRA_LAUNCH
,
action
.
isLaunchingApp
())
.
setFlags
(
Intent
.
FLAG_ACTIVITY_NO_HISTORY
);
int
reqCode
=
new
Random
()
.
nextInt
();
int
reqCode
=
random
.
nextInt
();
return
PendingIntent
.
getActivity
(
context
,
reqCode
,
intent
,
PendingIntent
.
FLAG_CANCEL_CURRENT
);
context
,
reqCode
,
intent
,
FLAG_CANCEL_CURRENT
);
}
}
src/android/notification/Manager.java
View file @
c967ea57
This diff is collapsed.
Click to expand it.
src/android/notification/Notification.java
View file @
c967ea57
...
...
@@ -21,7 +21,6 @@
package
de
.
appplant
.
cordova
.
plugin
.
notification
;
import
android.app.AlarmManager
;
import
android.app.NotificationManager
;
import
android.app.PendingIntent
;
...
...
@@ -30,6 +29,7 @@ import android.content.Context;
import
android.content.Intent
;
import
android.content.SharedPreferences
;
import
android.net.Uri
;
import
android.service.notification.StatusBarNotification
;
import
android.support.v4.app.NotificationCompat
;
import
android.support.v4.util.ArraySet
;
import
android.support.v4.util.Pair
;
...
...
@@ -63,7 +63,10 @@ public final class Notification {
public
static
final
String
EXTRA_ID
=
"NOTIFICATION_ID"
;
// Key for private preferences
static
final
String
PREF_KEY
=
"LocalNotification"
;
static
final
String
PREF_KEY_ID
=
"NOTIFICATION_ID"
;
// Key for private preferences
private
static
final
String
PREF_KEY_PID
=
"NOTIFICATION_PID"
;
// Application context passed by constructor
private
final
Context
context
;
...
...
@@ -127,42 +130,21 @@ public final class Notification {
return
getOptions
().
getTrigger
().
has
(
"every"
);
}
// /**
// * If the notification is scheduled.
// */
// public boolean isScheduled () {
// return isRepeating() || !wasInThePast();
// }
// /**
// * If the notification is triggered.
// */
// public boolean isTriggered () {
// return wasInThePast();
// }
// /**
// * If the notification is an update.
// *
// * @param keepFlag
// * Set to false to remove the flag from the option map
// */
// protected boolean isUpdate (boolean keepFlag) {
// boolean updated = options.getDict().optBoolean("updated", false);
// if (!keepFlag) {
// options.getDict().remove("updated");
// }
// return updated;
// }
// /**
// * Notification type can be one of pending or scheduled.
// */
// public Type getType () {
// return isScheduled() ? Type.SCHEDULED : Type.TRIGGERED;
// }
/**
* Notification type can be one of triggered or scheduled.
*/
public
Type
getType
()
{
StatusBarNotification
[]
toasts
=
getNotMgr
().
getActiveNotifications
();
int
id
=
getId
();
for
(
StatusBarNotification
toast
:
toasts
)
{
if
(
toast
.
getId
()
==
id
)
{
return
Type
.
TRIGGERED
;
}
}
return
Type
.
SCHEDULED
;
}
/**
* Schedule the local notification.
...
...
@@ -182,10 +164,11 @@ public final class Notification {
continue
;
Intent
intent
=
new
Intent
(
context
,
receiver
)
.
setAction
(
PREF_KEY
+
"#"
+
request
.
getIdentifier
())
.
setAction
(
PREF_KEY
_ID
+
request
.
getIdentifier
())
.
putExtra
(
Notification
.
EXTRA_ID
,
options
.
getId
())
.
putExtra
(
Request
.
EXTRA_OCCURRENCE
,
request
.
getOccurrence
());
ids
.
add
(
intent
.
getAction
());
intents
.
add
(
new
Pair
<
Date
,
Intent
>(
date
,
intent
));
}
while
(
request
.
moveNext
());
...
...
@@ -193,6 +176,8 @@ public final class Notification {
if
(
intents
.
isEmpty
())
return
;
persist
(
ids
);
Intent
last
=
intents
.
get
(
intents
.
size
()
-
1
).
second
;
last
.
putExtra
(
Request
.
EXTRA_LAST
,
true
);
...
...
@@ -219,14 +204,11 @@ public final class Notification {
mgr
.
setExact
(
RTC_WAKEUP
,
time
,
pi
);
break
;
}
ids
.
add
(
intent
.
getAction
());
}
catch
(
Exception
ignore
)
{
// Samsung devices have a known bug where a 500 alarms limit
// can crash the app
}
}
persist
(
ids
);
}
/**
...
...
@@ -253,7 +235,7 @@ public final class Notification {
/**
* Clear the local notification without canceling repeating alarms.
*/
public
void
clear
()
{
public
void
clear
()
{
getNotMgr
().
cancel
(
getId
());
if
(
isRepeating
())
...
...
@@ -271,8 +253,9 @@ public final class Notification {
* method and cancel it.
*/
public
void
cancel
()
{
Set
<
String
>
actions
=
getPrefs
().
getStringSet
(
"#"
+
options
.
getIdentifier
(),
null
);
SharedPreferences
prefs
=
getPrefs
(
PREF_KEY_PID
);
String
id
=
options
.
getIdentifier
();
Set
<
String
>
actions
=
prefs
.
getStringSet
(
id
,
null
);
unpersist
();
getNotMgr
().
cancel
(
options
.
getId
());
...
...
@@ -295,7 +278,7 @@ public final class Notification {
/**
* Present the local notification to user.
*/
public
void
show
()
{
public
void
show
()
{
if
(
builder
==
null
)
return
;
...
...
@@ -304,22 +287,6 @@ public final class Notification {
getNotMgr
().
notify
(
getId
(),
builder
.
build
());
}
// /**
// * Count of triggers since schedule.
// */
// public int getTriggerCountSinceSchedule() {
// long now = System.currentTimeMillis();
// long triggerTime = options.getTriggerTime();
// if (!wasInThePast())
// return 0;
// if (!isRepeating())
// return 1;
// return (int) ((now - triggerTime) / options.getRepeatInterval());
// }
/**
* Encode options to JSON.
*/
...
...
@@ -344,11 +311,15 @@ public final class Notification {
* @param ids List of intent actions to persist.
*/
private
void
persist
(
Set
<
String
>
ids
)
{
SharedPreferences
.
Editor
editor
=
getPrefs
().
edit
();
String
id
=
options
.
getIdentifier
();
SharedPreferences
.
Editor
editor
;
editor
=
getPrefs
(
PREF_KEY_ID
).
edit
();
editor
.
putString
(
id
,
options
.
toString
());
editor
.
putStringSet
(
"#"
+
id
,
ids
);
editor
.
apply
();
editor
=
getPrefs
(
PREF_KEY_PID
).
edit
();
editor
.
putStringSet
(
id
,
ids
);
editor
.
apply
();
}
...
...
@@ -356,13 +327,16 @@ public final class Notification {
* Remove the notification from the Android shared Preferences.
*/
private
void
unpersist
()
{
S
haredPreferences
.
Editor
editor
=
getPrefs
().
edit
()
;
S
tring
[]
keys
=
{
PREF_KEY_ID
,
PREF_KEY_PID
}
;
String
id
=
options
.
getIdentifier
();
SharedPreferences
.
Editor
editor
;
for
(
String
key
:
keys
)
{
editor
=
getPrefs
(
key
).
edit
();
editor
.
remove
(
id
);
editor
.
remove
(
"#"
+
id
);
editor
.
apply
();
}
}
/**
* Since Android 7 the app will crash if an external process has no
...
...
@@ -383,8 +357,8 @@ public final class Notification {
/**
* Shared private preferences for the application.
*/
private
SharedPreferences
getPrefs
()
{
return
context
.
getSharedPreferences
(
PREF_KEY
,
Context
.
MODE_PRIVATE
);
private
SharedPreferences
getPrefs
(
String
key
)
{
return
context
.
getSharedPreferences
(
key
,
Context
.
MODE_PRIVATE
);
}
/**
...
...
src/android/notification/Options.java
View file @
c967ea57
...
...
@@ -106,7 +106,7 @@ public final class Options {
/**
* Wrapped JSON object.
*/
JSONObject
getDict
()
{
public
JSONObject
getDict
()
{
return
options
;
}
...
...
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