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
69914bc6
Commit
69914bc6
authored
Oct 18, 2017
by
Sebastián Katzer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added back events such add, trigger, clear and click and action events
parent
519c452b
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
78 additions
and
39 deletions
+78
-39
ClickActivity.java
src/android/ClickActivity.java
+20
-8
LocalNotification.java
src/android/LocalNotification.java
+38
-24
Action.java
src/android/notification/Action.java
+5
-2
Builder.java
src/android/notification/Builder.java
+1
-0
AbstractClickActivity.java
src/android/notification/activity/AbstractClickActivity.java
+8
-3
ClickActivity.java
src/android/notification/activity/ClickActivity.java
+6
-2
No files found.
src/android/ClickActivity.java
View file @
69914bc6
...
...
@@ -21,6 +21,12 @@
package
de
.
appplant
.
cordova
.
plugin
.
localnotification
;
import
android.os.Bundle
;
import
android.support.v4.app.RemoteInput
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
import
de.appplant.cordova.plugin.notification.Notification
;
/**
...
...
@@ -33,19 +39,25 @@ public class ClickActivity extends de.appplant.cordova.plugin.notification.activ
/**
* Called when local notification was clicked by the user.
*
* @param notification Wrapper around the local notification
* @param action The name of the action.
* @param notification Wrapper around the local notification.
*/
@Override
public
void
onClick
(
Notification
notification
)
{
LocalNotification
.
fireEvent
(
"click"
,
notification
);
public
void
onClick
(
String
action
,
Notification
notification
)
{
JSONObject
data
=
new
JSONObject
();
Bundle
input
=
RemoteInput
.
getResultsFromIntent
(
getIntent
());
super
.
onClick
(
notification
);
if
(
input
!=
null
)
{
try
{
data
.
put
(
"text"
,
input
.
getString
(
action
,
""
));
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
}
}
if
(
notification
.
getOptions
().
isSticky
())
return
;
LocalNotification
.
fireEvent
(
action
,
notification
,
data
);
String
event
=
notification
.
isRepeating
()
?
"clear"
:
"cancel"
;
LocalNotification
.
fireEvent
(
event
,
notification
);
super
.
onClick
(
action
,
notification
);
}
}
src/android/LocalNotification.java
View file @
69914bc6
...
...
@@ -61,7 +61,7 @@ public class LocalNotification extends CordovaPlugin {
private
static
Boolean
deviceready
=
false
;
// To inform the user about the state of the app in callbacks
pr
otected
static
Boolean
isInBackground
=
true
;
pr
ivate
static
Boolean
isInBackground
=
true
;
// Queues all events before deviceready
private
static
ArrayList
<
String
>
eventQueue
=
new
ArrayList
<
String
>();
...
...
@@ -70,8 +70,6 @@ public class LocalNotification extends CordovaPlugin {
* Called after plugin construction and fields have been initialized.
* Prefer to use pluginInitialize instead since there is no value in
* having parameters on the initialize() function.
*
* pluginInitialize is not available for cordova 3.0-3.5 !
*/
@Override
public
void
initialize
(
CordovaInterface
cordova
,
CordovaWebView
webView
)
{
...
...
@@ -223,7 +221,7 @@ public class LocalNotification extends CordovaPlugin {
* JavaScript.
*/
private
void
check
(
CallbackContext
command
)
{
boolean
allowed
=
getNotificationMgr
().
hasPermission
();
boolean
allowed
=
getNotificationMgr
().
hasPermission
();
PluginResult
result
=
new
PluginResult
(
PluginResult
.
Status
.
OK
,
allowed
);
command
.
sendPluginResult
(
result
);
...
...
@@ -268,7 +266,7 @@ public class LocalNotification extends CordovaPlugin {
Notification
notification
=
mgr
.
schedule
(
request
,
TriggerReceiver
.
class
);
fireEvent
(
"
schedule
"
,
notification
);
fireEvent
(
"
add
"
,
notification
);
}
}
...
...
@@ -583,31 +581,56 @@ public class LocalNotification extends CordovaPlugin {
/**
* Fire given event on JS side. Does inform all event listeners.
*
* @param event
* The event name
* @param event The event name.
*/
private
void
fireEvent
(
String
event
)
{
fireEvent
(
event
,
null
);
fireEvent
(
event
,
null
,
new
JSONObject
()
);
}
/**
* Fire given event on JS side. Does inform all event listeners.
*
* @param event
The event name
* @param notification Optional notification to pass
the id and properties
.
* @param event
The event name.
* @param notification Optional notification to pass
with
.
*/
static
void
fireEvent
(
String
event
,
Notification
notification
)
{
String
state
=
getApplicationState
();
String
params
=
"\""
+
state
+
"\""
;
fireEvent
(
event
,
notification
,
new
JSONObject
());
}
/**
* Fire given event on JS side. Does inform all event listeners.
*
* @param event The event name.
* @param notification Optional notification to pass with.
* @param data Event object with additional data.
*/
static
void
fireEvent
(
String
event
,
Notification
notification
,
JSONObject
data
)
{
String
params
,
js
;
try
{
data
.
put
(
"event"
,
event
);
data
.
put
(
"foreground"
,
!
isInBackground
);
data
.
put
(
"queued"
,
!
deviceready
);
if
(
notification
!=
null
)
{
data
.
put
(
"notification"
,
notification
.
getId
());
}
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
}
if
(
notification
!=
null
)
{
params
=
notification
.
toString
()
+
","
+
params
;
params
=
notification
.
toString
()
+
","
+
data
.
toString
();
}
else
{
params
=
data
.
toString
();
}
String
js
=
"cordova.plugins.notification.local.core.fireEvent("
+
js
=
"cordova.plugins.notification.local.core.fireEvent("
+
"\""
+
event
+
"\","
+
params
+
")"
;
//
sendJavascript(js);
sendJavascript
(
js
);
}
/**
...
...
@@ -652,15 +675,6 @@ public class LocalNotification extends CordovaPlugin {
// }
/**
* Current application state.
*
* @return "background" or "foreground"
*/
static
String
getApplicationState
()
{
return
isInBackground
?
"background"
:
"foreground"
;
}
/**
* Notification manager instance.
*/
private
Manager
getNotificationMgr
()
{
...
...
src/android/notification/Action.java
View file @
69914bc6
...
...
@@ -35,10 +35,13 @@ import de.appplant.cordova.plugin.notification.util.AssetUtil;
* that it may be generated each time the notification is built. Necessary to
* compensate for missing functionality in the support library.
*/
final
class
Action
{
public
final
class
Action
{
// Key name for bundled extras
static
final
String
EXTRA
=
"NOTIFICATION_ACTION_ID"
;
public
static
final
String
EXTRA
=
"NOTIFICATION_ACTION_ID"
;
// The id for the click action
public
static
final
String
CLICK_ACTION_ID
=
"click"
;
// The application context
private
final
Context
context
;
...
...
src/android/notification/Builder.java
View file @
69914bc6
...
...
@@ -279,6 +279,7 @@ public final class Builder {
Intent
intent
=
new
Intent
(
context
,
clickActivity
)
.
putExtra
(
Options
.
EXTRA
,
options
.
toString
())
.
putExtra
(
Action
.
EXTRA
,
Action
.
CLICK_ACTION_ID
)
.
setFlags
(
Intent
.
FLAG_ACTIVITY_NO_HISTORY
);
int
reqCode
=
new
Random
().
nextInt
();
...
...
src/android/notification/activity/AbstractClickActivity.java
View file @
69914bc6
...
...
@@ -29,9 +29,12 @@ import android.os.Bundle;
import
org.json.JSONException
;
import
org.json.JSONObject
;
import
de.appplant.cordova.plugin.notification.Action
;
import
de.appplant.cordova.plugin.notification.Notification
;
import
de.appplant.cordova.plugin.notification.Options
;
import
static
de
.
appplant
.
cordova
.
plugin
.
notification
.
Action
.
CLICK_ACTION_ID
;
/**
* Abstract content receiver activity for local notifications. Creates the
* local notification and calls the event functions for further proceeding.
...
...
@@ -52,6 +55,7 @@ abstract public class AbstractClickActivity extends Activity {
Context
context
=
getApplicationContext
();
try
{
String
action
=
bundle
.
getString
(
Action
.
EXTRA
,
CLICK_ACTION_ID
);
String
data
=
bundle
.
getString
(
Options
.
EXTRA
);
JSONObject
dict
=
new
JSONObject
(
data
);
Options
options
=
new
Options
(
context
,
dict
);
...
...
@@ -59,7 +63,7 @@ abstract public class AbstractClickActivity extends Activity {
Notification
notification
=
new
Notification
(
context
,
options
);
onClick
(
notification
);
onClick
(
action
,
notification
);
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
}
...
...
@@ -78,9 +82,10 @@ abstract public class AbstractClickActivity extends Activity {
/**
* Called when local notification was clicked by the user.
*
* @param notification Wrapper around the local notification
* @param action The name of the action.
* @param notification Wrapper around the local notification.
*/
abstract
public
void
onClick
(
Notification
notification
);
abstract
public
void
onClick
(
String
action
,
Notification
notification
);
/**
* Launch main intent from package.
...
...
src/android/notification/activity/ClickActivity.java
View file @
69914bc6
...
...
@@ -34,12 +34,16 @@ public class ClickActivity extends AbstractClickActivity {
* Called when local notification was clicked by the user. Will
* move the app to foreground.
*
* @param notification Wrapper around the local notification
* @param action The name of the action.
* @param notification Wrapper around the local notification.
*/
@Override
public
void
onClick
(
Notification
notification
)
{
public
void
onClick
(
String
action
,
Notification
notification
)
{
launchApp
();
if
(
notification
.
getOptions
().
isSticky
())
return
;
if
(
notification
.
isRepeating
())
{
notification
.
clear
();
}
else
{
...
...
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