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
bd95db8f
Commit
bd95db8f
authored
Dec 02, 2013
by
Sebastián Katzer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Get the `background` callback on Android to work!
parent
d4fcd269
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
75 additions
and
17 deletions
+75
-17
plugin.xml
plugin.xml
+8
-0
Receiver.java
src/android/Receiver.java
+4
-17
ReceiverActivity.java
src/android/ReceiverActivity.java
+63
-0
No files found.
plugin.xml
View file @
bd95db8f
...
...
@@ -63,6 +63,13 @@
<action
android:name=
"android.intent.action.BOOT_COMPLETED"
/>
</intent-filter>
</receiver>
<!--
* The receiver activity is triggered when a notification is clicked by a user.
* The activity calls the background callback and brings the launch inten
* up to foreground.
-->
<activity
android:name=
"de.appplant.cordova.plugin.localnotification.ReceiverActivity"
></activity>
</config-file>
<config-file
target=
"AndroidManifest.xml"
parent=
"/manifest"
>
...
...
@@ -74,6 +81,7 @@
<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/ReceiverActivity.java"
target-dir=
"src/de/appplant/cordova/plugin/localnotification"
/>
</platform>
<!-- wp8 -->
...
...
src/android/Receiver.java
View file @
bd95db8f
...
...
@@ -115,9 +115,10 @@ public class Receiver extends BroadcastReceiver {
* Fügt der Notification einen onclick Handler hinzu.
*/
private
Builder
setClickEvent
(
Builder
notification
)
{
String
packageName
=
context
.
getPackageName
();
Intent
launchIntent
=
context
.
getPackageManager
().
getLaunchIntentForPackage
(
packageName
);
PendingIntent
contentIntent
=
PendingIntent
.
getActivity
(
context
,
0
,
launchIntent
,
PendingIntent
.
FLAG_UPDATE_CURRENT
);
Intent
intent
=
new
Intent
(
context
,
ReceiverActivity
.
class
)
.
putExtra
(
OPTIONS
,
options
.
getJSONObject
().
toString
());
PendingIntent
contentIntent
=
PendingIntent
.
getActivity
(
context
,
0
,
intent
,
PendingIntent
.
FLAG_CANCEL_CURRENT
);
return
notification
.
setContentIntent
(
contentIntent
);
}
...
...
@@ -163,17 +164,4 @@ public class Receiver extends BroadcastReceiver {
LocalNotification
.
webView
.
sendJavascript
(
function
+
"("
+
options
.
getId
()
+
")"
);
}
}
/**
* Ruft die `background` Callback Funktion auf.
*/
private
void
invokeBackgroundCallback
()
{
String
function
=
options
.
getBackground
();
// after reboot, LocalNotification.webView is always null
// may be call background callback later
if
(
function
!=
null
&&
LocalNotification
.
webView
!=
null
)
{
LocalNotification
.
webView
.
sendJavascript
(
function
+
"("
+
options
.
getId
()
+
")"
);
}
}
}
\ No newline at end of file
src/android/ReceiverActivity.java
0 → 100644
View file @
bd95db8f
/**
* 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
org.json.JSONException
;
import
org.json.JSONObject
;
import
android.app.Activity
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.os.Bundle
;
public
class
ReceiverActivity
extends
Activity
{
/** Called when the activity is first created. */
@Override
public
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
Intent
intent
=
this
.
getIntent
();
Bundle
bundle
=
intent
.
getExtras
();
try
{
JSONObject
args
=
new
JSONObject
(
bundle
.
getString
(
Receiver
.
OPTIONS
));
Options
options
=
new
Options
(
getApplicationContext
()).
parse
(
args
);
invokeBackgroundCallback
(
options
);
launchMainIntent
();
}
catch
(
JSONException
e
)
{}
}
/**
* Launch main intent for package.
*/
private
void
launchMainIntent
()
{
Context
context
=
getApplicationContext
();
String
packageName
=
context
.
getPackageName
();
Intent
launchIntent
=
context
.
getPackageManager
().
getLaunchIntentForPackage
(
packageName
);
launchIntent
.
addFlags
(
Intent
.
FLAG_ACTIVITY_REORDER_TO_FRONT
|
Intent
.
FLAG_ACTIVITY_SINGLE_TOP
);
context
.
startActivity
(
launchIntent
);
}
/**
* Ruft die `background` Callback Funktion auf.
*/
private
void
invokeBackgroundCallback
(
Options
options
)
{
String
function
=
options
.
getBackground
();
// after reboot, LocalNotification.webView is always null
// may be call background callback later
if
(
function
!=
null
&&
LocalNotification
.
webView
!=
null
)
{
LocalNotification
.
webView
.
sendJavascript
(
function
+
"("
+
options
.
getId
()
+
")"
);
}
}
}
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