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
8d210378
Commit
8d210378
authored
Dec 01, 2013
by
Sebastián Katzer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removed Helper.java class
parent
78308f18
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
79 additions
and
173 deletions
+79
-173
plugin.xml
plugin.xml
+0
-1
Helper.java
src/android/Helper.java
+0
-154
LocalNotification.java
src/android/LocalNotification.java
+79
-18
No files found.
plugin.xml
View file @
8d210378
...
...
@@ -74,7 +74,6 @@
<source-file
src=
"src/android/Receiver.java"
target-dir=
"src/de/appplant/cordova/plugin/localnotification"
/>
<source-file
src=
"src/android/Options.java"
target-dir=
"src/de/appplant/cordova/plugin/localnotification"
/>
<source-file
src=
"src/android/Restore.java"
target-dir=
"src/de/appplant/cordova/plugin/localnotification"
/>
<source-file
src=
"src/android/Helper.java"
target-dir=
"src/de/appplant/cordova/plugin/localnotification"
/>
</platform>
<!-- wp8 -->
...
...
src/android/Helper.java
deleted
100644 → 0
View file @
78308f18
/**
* Cordova LocalNotification Plugin
*
* Created by Sebastian Katzer (github.com/katzer).
* Copyright 2013 Sebastian Katzer. All rights reserved.
* LGPL v2.1 licensed
*/
package
de
.
appplant
.
cordova
.
plugin
.
localnotification
;
import
java.util.Map
;
import
java.util.Set
;
import
org.json.JSONArray
;
import
android.app.AlarmManager
;
import
android.app.NotificationManager
;
import
android.app.PendingIntent
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.content.SharedPreferences
;
import
android.content.SharedPreferences.Editor
;
public
class
Helper
{
private
Context
context
;
public
Helper
(
Context
context
)
{
this
.
context
=
context
;
}
/**
* Set an alarm.
*
* @param options
* The options that can be specified per alarm.
*/
public
void
add
(
Options
options
)
{
long
triggerTime
=
options
.
getDate
();
Intent
intent
=
new
Intent
(
context
,
Receiver
.
class
)
.
setAction
(
""
+
options
.
getId
())
.
putExtra
(
Receiver
.
OPTIONS
,
options
.
getJSONObject
().
toString
());
AlarmManager
am
=
getAlarmManager
();
PendingIntent
pi
=
PendingIntent
.
getBroadcast
(
context
,
0
,
intent
,
PendingIntent
.
FLAG_CANCEL_CURRENT
);
if
(
options
.
getInterval
()
>
0
)
{
am
.
setRepeating
(
AlarmManager
.
RTC_WAKEUP
,
triggerTime
,
options
.
getInterval
(),
pi
);
}
else
{
am
.
set
(
AlarmManager
.
RTC_WAKEUP
,
triggerTime
,
pi
);
}
}
/**
* Cancel a specific notification that was previously registered.
*
* @param notificationId
* The original ID of the notification that was used when it was
* registered using add()
*/
public
void
cancel
(
String
notificationId
)
{
/*
* Create an intent that looks similar, to the one that was registered
* using add. 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.
*/
Intent
intent
=
new
Intent
(
context
,
Receiver
.
class
)
.
setAction
(
""
+
notificationId
);
PendingIntent
pi
=
PendingIntent
.
getBroadcast
(
context
,
0
,
intent
,
PendingIntent
.
FLAG_CANCEL_CURRENT
);
AlarmManager
am
=
getAlarmManager
();
NotificationManager
nc
=
getNotificationManager
();
am
.
cancel
(
pi
);
nc
.
cancel
(
Integer
.
parseInt
(
notificationId
));
}
/**
* Cancel all notifications that were created by this plugin.
*
* Android can only unregister a specific alarm. There is no such thing
* as cancelAll. Therefore we rely on the Shared Preferences which holds
* all our alarms to loop through these alarms and unregister them one
* by one.
*/
public
void
cancelAll
()
{
SharedPreferences
settings
=
LocalNotification
.
getSharedPreferences
();
NotificationManager
nc
=
getNotificationManager
();
Map
<
String
,
?>
alarms
=
settings
.
getAll
();
Set
<
String
>
alarmIds
=
alarms
.
keySet
();
for
(
String
alarmId
:
alarmIds
)
{
cancel
(
alarmId
);
}
nc
.
cancelAll
();
}
/**
* Persist the information of this alarm to the Android Shared Preferences.
* This will allow the application to restore the alarm upon device reboot.
* Also this is used by the cancelAll method.
*
* @param alarmId
* The Id of the notification that must be persisted.
* @param args
* The assumption is that parse has been called already.
*/
public
void
persist
(
String
alarmId
,
JSONArray
args
)
{
Editor
editor
=
LocalNotification
.
getSharedPreferences
().
edit
();
if
(
alarmId
!=
null
)
{
editor
.
putString
(
alarmId
,
args
.
toString
());
editor
.
commit
();
}
}
/**
* Remove a specific alarm from the Android shared Preferences.
*
* @param alarmId
* The Id of the notification that must be removed.
*/
public
void
unpersist
(
String
alarmId
)
{
Editor
editor
=
LocalNotification
.
getSharedPreferences
().
edit
();
if
(
alarmId
!=
null
)
{
editor
.
remove
(
alarmId
);
editor
.
commit
();
}
}
/**
* Clear all alarms from the Android shared Preferences.
*/
public
void
unpersistAll
()
{
Editor
editor
=
LocalNotification
.
getSharedPreferences
().
edit
();
editor
.
clear
();
editor
.
commit
();
}
private
AlarmManager
getAlarmManager
()
{
return
(
AlarmManager
)
context
.
getSystemService
(
Context
.
ALARM_SERVICE
);
}
private
NotificationManager
getNotificationManager
()
{
return
(
NotificationManager
)
context
.
getSystemService
(
Context
.
NOTIFICATION_SERVICE
);
}
}
\ No newline at end of file
src/android/LocalNotification.java
View file @
8d210378
...
...
@@ -8,16 +8,23 @@
package
de
.
appplant
.
cordova
.
plugin
.
localnotification
;
import
java.util.Map
;
import
java.util.Set
;
import
org.apache.cordova.CallbackContext
;
import
org.apache.cordova.CordovaPlugin
;
import
org.apache.cordova.CordovaWebView
;
import
org.json.JSONArray
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
import
android.app.AlarmManager
;
import
android.app.NotificationManager
;
import
android.app.PendingIntent
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.content.SharedPreferences
;
import
org.apache.cordova.CordovaPlugin
;
import
org.apache.cordova.CallbackContext
;
import
org.apache.cordova.CordovaWebView
;
import
android.content.SharedPreferences.Editor
;
/**
* This plugin utilizes the Android AlarmManager in combination with StatusBar
...
...
@@ -34,7 +41,8 @@ public class LocalNotification extends CordovaPlugin {
@Override
public
boolean
execute
(
String
action
,
JSONArray
args
,
CallbackContext
callbackContext
)
throws
JSONException
{
rememberCordovaVarsForStaticUse
();
LocalNotification
.
webView
=
super
.
webView
;
LocalNotification
.
context
=
super
.
cordova
.
getActivity
().
getApplicationContext
();
if
(
action
.
equalsIgnoreCase
(
"add"
))
{
JSONObject
arguments
=
args
.
optJSONObject
(
0
);
...
...
@@ -78,7 +86,20 @@ public class LocalNotification extends CordovaPlugin {
* The options that can be specified per alarm.
*/
public
static
void
add
(
Options
options
)
{
getHelper
().
add
(
options
);
long
triggerTime
=
options
.
getDate
();
Intent
intent
=
new
Intent
(
context
,
Receiver
.
class
)
.
setAction
(
""
+
options
.
getId
())
.
putExtra
(
Receiver
.
OPTIONS
,
options
.
getJSONObject
().
toString
());
AlarmManager
am
=
getAlarmManager
();
PendingIntent
pi
=
PendingIntent
.
getBroadcast
(
context
,
0
,
intent
,
PendingIntent
.
FLAG_CANCEL_CURRENT
);
if
(
options
.
getInterval
()
>
0
)
{
am
.
setRepeating
(
AlarmManager
.
RTC_WAKEUP
,
triggerTime
,
options
.
getInterval
(),
pi
);
}
else
{
am
.
set
(
AlarmManager
.
RTC_WAKEUP
,
triggerTime
,
pi
);
}
}
/**
...
...
@@ -89,7 +110,22 @@ public class LocalNotification extends CordovaPlugin {
* registered using add()
*/
public
static
void
cancel
(
String
notificationId
)
{
getHelper
().
cancel
(
notificationId
);
/*
* Create an intent that looks similar, to the one that was registered
* using add. 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.
*/
Intent
intent
=
new
Intent
(
context
,
Receiver
.
class
)
.
setAction
(
""
+
notificationId
);
PendingIntent
pi
=
PendingIntent
.
getBroadcast
(
context
,
0
,
intent
,
PendingIntent
.
FLAG_CANCEL_CURRENT
);
AlarmManager
am
=
getAlarmManager
();
NotificationManager
nc
=
getNotificationManager
();
am
.
cancel
(
pi
);
nc
.
cancel
(
Integer
.
parseInt
(
notificationId
));
}
/**
...
...
@@ -101,7 +137,16 @@ public class LocalNotification extends CordovaPlugin {
* by one.
*/
public
static
void
cancelAll
()
{
getHelper
().
cancelAll
();
SharedPreferences
settings
=
getSharedPreferences
();
NotificationManager
nc
=
getNotificationManager
();
Map
<
String
,
?>
alarms
=
settings
.
getAll
();
Set
<
String
>
alarmIds
=
alarms
.
keySet
();
for
(
String
alarmId
:
alarmIds
)
{
cancel
(
alarmId
);
}
nc
.
cancelAll
();
}
/**
...
...
@@ -115,7 +160,12 @@ public class LocalNotification extends CordovaPlugin {
* The assumption is that parse has been called already.
*/
public
static
void
persist
(
String
alarmId
,
JSONArray
args
)
{
getHelper
().
persist
(
alarmId
,
args
);
Editor
editor
=
getSharedPreferences
().
edit
();
if
(
alarmId
!=
null
)
{
editor
.
putString
(
alarmId
,
args
.
toString
());
editor
.
commit
();
}
}
/**
...
...
@@ -125,32 +175,42 @@ public class LocalNotification extends CordovaPlugin {
* The Id of the notification that must be removed.
*/
public
static
void
unpersist
(
String
alarmId
)
{
getHelper
().
unpersist
(
alarmId
);
Editor
editor
=
getSharedPreferences
().
edit
();
if
(
alarmId
!=
null
)
{
editor
.
remove
(
alarmId
);
editor
.
commit
();
}
}
/**
* Clear all alarms from the Android shared Preferences.
*/
public
static
void
unpersistAll
()
{
getHelper
().
unpersistAll
();
Editor
editor
=
LocalNotification
.
getSharedPreferences
().
edit
();
editor
.
clear
();
editor
.
commit
();
}
/**
*
Local storage of
the application.
*
The Local storage for
the application.
*/
public
static
SharedPreferences
getSharedPreferences
()
{
return
context
.
getSharedPreferences
(
PLUGIN_NAME
,
Context
.
MODE_PRIVATE
);
}
private
final
static
Helper
getHelper
()
{
return
new
Helper
(
context
);
/**
* The alarm manager for the application.
*/
private
static
AlarmManager
getAlarmManager
()
{
return
(
AlarmManager
)
context
.
getSystemService
(
Context
.
ALARM_SERVICE
);
}
/**
*
Save required Cordova specific variables for later use
.
*
The notification manager for the application
.
*/
private
void
rememberCordovaVarsForStaticUse
()
{
LocalNotification
.
webView
=
super
.
webView
;
LocalNotification
.
context
=
super
.
cordova
.
getActivity
().
getApplicationContext
();
private
static
NotificationManager
getNotificationManager
()
{
return
(
NotificationManager
)
context
.
getSystemService
(
Context
.
NOTIFICATION_SERVICE
);
}
}
\ No newline at end of file
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