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
2d2ce205
Commit
2d2ce205
authored
Jan 12, 2015
by
PKnittel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Transferred the showNotification-Function to NotificationWrapper-Class
parent
e364b93b
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
49 additions
and
45 deletions
+49
-45
Receiver.java
src/android/Receiver.java
+5
-3
NotificationBuilder.java
src/android/notification/NotificationBuilder.java
+3
-42
NotificationWrapper.java
src/android/notification/NotificationWrapper.java
+41
-0
No files found.
src/android/Receiver.java
View file @
2d2ce205
...
...
@@ -32,6 +32,8 @@ import android.content.Context;
import
android.content.Intent
;
import
android.os.Bundle
;
import
android.support.v4.app.NotificationCompat.Builder
;
import
de.appplant.cordova.plugin.notification.*
;
/**
...
...
@@ -80,12 +82,12 @@ public class Receiver extends BroadcastReceiver {
if
(
options
.
getInterval
()
==
0
)
{
LocalNotification
.
unpersist
(
options
.
getId
());
}
builder
.
showNotificationToast
(
);
nWrapper
.
showNotificationToast
(
options
);
fireTriggerEvent
();
}
else
{
builder
.
buildNotification
();
Builder
notification
=
builder
.
buildNotification
();
builder
.
showNotification
(
);
nWrapper
.
showNotification
(
notification
,
options
);
}
}
...
...
src/android/notification/NotificationBuilder.java
View file @
2d2ce205
...
...
@@ -23,7 +23,6 @@ package de.appplant.cordova.plugin.notification;
import
java.util.Random
;
import
android.annotation.SuppressLint
;
import
android.app.NotificationManager
;
import
android.app.PendingIntent
;
import
android.content.Context
;
import
android.content.Intent
;
...
...
@@ -31,7 +30,6 @@ import android.net.Uri;
import
android.os.Build
;
import
android.support.v4.app.NotificationCompat
;
import
android.support.v4.app.NotificationCompat.Builder
;
import
android.widget.Toast
;
public
class
NotificationBuilder
{
private
Options
options
;
...
...
@@ -62,7 +60,7 @@ public class NotificationBuilder {
* Creates the notification.
*/
@SuppressLint
(
"NewApi"
)
public
void
buildNotification
()
{
public
Builder
buildNotification
()
{
Uri
sound
=
options
.
getSound
();
//DeleteIntent is called when the user clears a notification manually
...
...
@@ -94,6 +92,8 @@ public class NotificationBuilder {
}
setClickEvent
(
notification
);
return
notification
;
}
/**
...
...
@@ -111,43 +111,4 @@ public class NotificationBuilder {
return
notification
.
setContentIntent
(
contentIntent
);
}
/**
* Shows the notification
*/
@SuppressWarnings
(
"deprecation"
)
public
void
showNotification
()
{
NotificationManager
mgr
=
(
NotificationManager
)
context
.
getSystemService
(
Context
.
NOTIFICATION_SERVICE
);
int
id
=
0
;
try
{
id
=
Integer
.
parseInt
(
options
.
getId
());
}
catch
(
Exception
e
)
{}
if
(
Build
.
VERSION
.
SDK_INT
<
16
)
{
// build notification for HoneyComb to ICS
mgr
.
notify
(
id
,
notification
.
getNotification
());
}
else
if
(
Build
.
VERSION
.
SDK_INT
>
15
)
{
// Notification for Jellybean and above
mgr
.
notify
(
id
,
notification
.
build
());
}
}
/**
* Show a notification as a Toast when App is runing in foreground
* @param title Title of the notification
* @param notification Notification to show
*/
public
void
showNotificationToast
(){
String
title
=
options
.
getTitle
();
String
message
=
options
.
getMessage
();
int
duration
=
Toast
.
LENGTH_LONG
;
if
(
title
.
equals
(
""
)){
title
=
"Notification"
;
}
String
text
=
title
+
" \n "
+
message
;
Toast
notificationToast
=
Toast
.
makeText
(
context
,
text
,
duration
);
notificationToast
.
show
();
}
}
src/android/notification/NotificationWrapper.java
View file @
2d2ce205
...
...
@@ -36,6 +36,8 @@ import android.content.Intent;
import
android.content.SharedPreferences
;
import
android.content.SharedPreferences.Editor
;
import
android.os.Build
;
import
android.support.v4.app.NotificationCompat.Builder
;
import
android.widget.Toast
;
/**
* Wrapper class to schedule, cancel, clear, and update notifications.
...
...
@@ -207,6 +209,45 @@ public class NotificationWrapper {
nc
.
cancelAll
();
}
/**
* Shows the notification
*/
@SuppressWarnings
(
"deprecation"
)
public
void
showNotification
(
Builder
notification
,
Options
options
)
{
NotificationManager
mgr
=
(
NotificationManager
)
context
.
getSystemService
(
Context
.
NOTIFICATION_SERVICE
);
int
id
=
0
;
try
{
id
=
Integer
.
parseInt
(
options
.
getId
());
}
catch
(
Exception
e
)
{}
if
(
Build
.
VERSION
.
SDK_INT
<
16
)
{
// build notification for HoneyComb to ICS
mgr
.
notify
(
id
,
notification
.
getNotification
());
}
else
if
(
Build
.
VERSION
.
SDK_INT
>
15
)
{
// Notification for Jellybean and above
mgr
.
notify
(
id
,
notification
.
build
());
}
}
/**
* Show a notification as a Toast when App is runing in foreground
* @param title Title of the notification
* @param notification Notification to show
*/
public
void
showNotificationToast
(
Options
options
){
String
title
=
options
.
getTitle
();
String
message
=
options
.
getMessage
();
int
duration
=
Toast
.
LENGTH_LONG
;
if
(
title
.
equals
(
""
)){
title
=
"Notification"
;
}
String
text
=
title
+
" \n "
+
message
;
Toast
notificationToast
=
Toast
.
makeText
(
context
,
text
,
duration
);
notificationToast
.
show
();
}
//---------------Manage Shared Preferences---------------------------------------------------
/**
...
...
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