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
be881a56
Commit
be881a56
authored
Oct 23, 2017
by
Sebastián Katzer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support for native badges on Android via badge plugin
parent
e02b0c7e
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
64 additions
and
3 deletions
+64
-3
plugin.xml
plugin.xml
+3
-1
TriggerReceiver.java
src/android/TriggerReceiver.java
+7
-0
localnotification.gradle
src/android/build/localnotification.gradle
+28
-0
Builder.java
src/android/notification/Builder.java
+1
-1
Manager.java
src/android/notification/Manager.java
+16
-0
Options.java
src/android/notification/Options.java
+8
-1
local-notification-util.js
www/local-notification-util.js
+1
-0
No files found.
plugin.xml
View file @
be881a56
...
@@ -43,12 +43,13 @@
...
@@ -43,12 +43,13 @@
<engine
name=
"cordova"
version=
">=3.6.0"
/>
<engine
name=
"cordova"
version=
">=3.6.0"
/>
<engine
name=
"cordova-plugman"
version=
">=4.3.0"
/>
<engine
name=
"cordova-plugman"
version=
">=4.3.0"
/>
<engine
name=
"cordova-windows"
version=
">=4.2.0"
/>
<engine
name=
"cordova-windows"
version=
">=4.2.0"
/>
<engine
name=
"apple-ios"
version=
">=10.0.0"
/>
<engine
name=
"cordova-android"
version=
">=6.0.0"
/>
<engine
name=
"cordova-android"
version=
">=6.0.0"
/>
<engine
name=
"apple-ios"
version=
">=10.0.0"
/>
</engines>
</engines>
<!-- dependencies -->
<!-- dependencies -->
<dependency
id=
"cordova-plugin-device"
/>
<dependency
id=
"cordova-plugin-device"
/>
<dependency
id=
"cordova-plugin-badge"
version=
">=0.8.5"
/>
<!-- js -->
<!-- js -->
<js-module
src=
"www/local-notification.js"
name=
"LocalNotification"
>
<js-module
src=
"www/local-notification.js"
name=
"LocalNotification"
>
...
@@ -96,6 +97,7 @@
...
@@ -96,6 +97,7 @@
<!-- android -->
<!-- android -->
<platform
name=
"android"
>
<platform
name=
"android"
>
<framework
src=
"com.android.support:support-v4:26.+"
value=
"gradle"
/>
<framework
src=
"com.android.support:support-v4:26.+"
value=
"gradle"
/>
<framework
src=
"src/android/build/localnotification.gradle"
custom=
"true"
type=
"gradleReference"
/>
<config-file
target=
"res/xml/config.xml"
parent=
"/*"
>
<config-file
target=
"res/xml/config.xml"
parent=
"/*"
>
<feature
name=
"LocalNotification"
>
<feature
name=
"LocalNotification"
>
...
...
src/android/TriggerReceiver.java
View file @
be881a56
...
@@ -24,6 +24,7 @@ package de.appplant.cordova.plugin.localnotification;
...
@@ -24,6 +24,7 @@ package de.appplant.cordova.plugin.localnotification;
import
android.os.Bundle
;
import
android.os.Bundle
;
import
de.appplant.cordova.plugin.notification.Builder
;
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.Notification
;
import
de.appplant.cordova.plugin.notification.receiver.AbstractTriggerReceiver
;
import
de.appplant.cordova.plugin.notification.receiver.AbstractTriggerReceiver
;
...
@@ -44,6 +45,12 @@ public class TriggerReceiver extends AbstractTriggerReceiver {
...
@@ -44,6 +45,12 @@ public class TriggerReceiver extends AbstractTriggerReceiver {
*/
*/
@Override
@Override
public
void
onTrigger
(
Notification
notification
,
Bundle
bundle
)
{
public
void
onTrigger
(
Notification
notification
,
Bundle
bundle
)
{
int
badge
=
notification
.
getOptions
().
getBadgeNumber
();
if
(
badge
>
0
)
{
Manager
.
getInstance
(
notification
.
getContext
()).
setBadge
(
badge
);
}
notification
.
show
();
notification
.
show
();
LocalNotification
.
fireEvent
(
"trigger"
,
notification
);
LocalNotification
.
fireEvent
(
"trigger"
,
notification
);
}
}
...
...
src/android/build/localnotification.gradle
0 → 100644
View file @
be881a56
/*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apache License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://opensource.org/licenses/Apache-2.0/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*/
repositories
{
mavenCentral
()
}
if
(!
project
.
ext
.
has
(
'appShortcutBadgerVersion'
))
{
ext
.
appShortcutBadgerVersion
=
'1.1.19'
}
dependencies
{
compile
"me.leolin:ShortcutBadger:${appShortcutBadgerVersion}@aar"
}
src/android/notification/Builder.java
View file @
be881a56
...
@@ -123,7 +123,7 @@ public final class Builder {
...
@@ -123,7 +123,7 @@ public final class Builder {
.
setContentTitle
(
options
.
getTitle
())
.
setContentTitle
(
options
.
getTitle
())
.
setContentText
(
options
.
getText
())
.
setContentText
(
options
.
getText
())
.
setTicker
(
options
.
getText
())
.
setTicker
(
options
.
getText
())
.
setNumber
(
options
.
get
Badge
Number
())
.
setNumber
(
options
.
getNumber
())
.
setAutoCancel
(
options
.
isAutoClear
())
.
setAutoCancel
(
options
.
isAutoClear
())
.
setOngoing
(
options
.
isSticky
())
.
setOngoing
(
options
.
isSticky
())
.
setColor
(
options
.
getColor
())
.
setColor
(
options
.
getColor
())
...
...
src/android/notification/Manager.java
View file @
be881a56
...
@@ -30,6 +30,8 @@ import android.support.v4.app.NotificationManagerCompat;
...
@@ -30,6 +30,8 @@ import android.support.v4.app.NotificationManagerCompat;
import
org.json.JSONException
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
import
org.json.JSONObject
;
import
de.appplant.cordova.plugin.badge.BadgeImpl
;
import
static
android
.
os
.
Build
.
VERSION
.
SDK_INT
;
import
static
android
.
os
.
Build
.
VERSION
.
SDK_INT
;
import
static
android
.
os
.
Build
.
VERSION_CODES
.
O
;
import
static
android
.
os
.
Build
.
VERSION_CODES
.
O
;
import
static
android
.
support
.
v4
.
app
.
NotificationManagerCompat
.
IMPORTANCE_DEFAULT
;
import
static
android
.
support
.
v4
.
app
.
NotificationManagerCompat
.
IMPORTANCE_DEFAULT
;
...
@@ -160,6 +162,7 @@ public final class Manager {
...
@@ -160,6 +162,7 @@ public final class Manager {
*/
*/
public
void
clearAll
()
{
public
void
clearAll
()
{
getNotCompMgr
().
cancelAll
();
getNotCompMgr
().
cancelAll
();
setBadge
(
0
);
}
}
// /**
// /**
...
@@ -462,6 +465,19 @@ public final class Manager {
...
@@ -462,6 +465,19 @@ public final class Manager {
// }
// }
/**
/**
* Set the badge number of the app icon.
*
* @param badge The badge number.
*/
public
void
setBadge
(
int
badge
)
{
if
(
badge
==
0
)
{
new
BadgeImpl
(
context
).
clearBadge
();
}
else
{
new
BadgeImpl
(
context
).
setBadge
(
badge
);
}
}
/**
* Shared private preferences for the application.
* Shared private preferences for the application.
*/
*/
private
SharedPreferences
getPrefs
()
{
private
SharedPreferences
getPrefs
()
{
...
...
src/android/notification/Options.java
View file @
be881a56
...
@@ -138,11 +138,18 @@ public final class Options {
...
@@ -138,11 +138,18 @@ public final class Options {
/**
/**
* Badge number for the local notification.
* Badge number for the local notification.
*/
*/
int
getBadgeNumber
()
{
public
int
getBadgeNumber
()
{
return
options
.
optInt
(
"badge"
,
0
);
return
options
.
optInt
(
"badge"
,
0
);
}
}
/**
/**
* Number for the local notification.
*/
public
int
getNumber
()
{
return
options
.
optInt
(
"number"
,
0
);
}
/**
* ongoing flag for local notifications.
* ongoing flag for local notifications.
*/
*/
public
Boolean
isSticky
()
{
public
Boolean
isSticky
()
{
...
...
www/local-notification-util.js
View file @
be881a56
...
@@ -66,6 +66,7 @@ exports.applyPlatformSpecificOptions = function () {
...
@@ -66,6 +66,7 @@ exports.applyPlatformSpecificOptions = function () {
defaults
.
showWhen
=
true
;
defaults
.
showWhen
=
true
;
defaults
.
defaults
=
0
;
defaults
.
defaults
=
0
;
defaults
.
priority
=
0
;
defaults
.
priority
=
0
;
defaults
.
number
=
0
;
defaults
.
channel
=
undefined
;
defaults
.
channel
=
undefined
;
defaults
.
launch
=
true
;
defaults
.
launch
=
true
;
break
;
break
;
...
...
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