Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
InstiApp
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
RAHUL SHARMA
InstiApp
Commits
0209bbaf
Commit
0209bbaf
authored
Sep 30, 2018
by
Varun Patil
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make event about to start notification
parent
cd68a18a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
17 deletions
+28
-17
app/src/main/java/app/insti/InstiAppFirebaseMessagingService.java
...main/java/app/insti/InstiAppFirebaseMessagingService.java
+28
-17
No files found.
app/src/main/java/app/insti/InstiAppFirebaseMessagingService.java
View file @
0209bbaf
...
...
@@ -66,23 +66,24 @@ public class InstiAppFirebaseMessagingService extends FirebaseMessagingService {
super
.
onMessageReceived
(
remoteMessage
);
}
/** Ensure key is in data */
private
boolean
ensureKeyExists
(
RemoteMessage
remoteMessage
,
String
key
)
{
return
(
remoteMessage
.
getData
().
get
(
key
)
!=
null
);
}
/** Send a event is starting notification */
private
void
sendEventStartingNotification
(
RemoteMessage
remoteMessage
)
{
if
(!
ensureKeyExists
(
remoteMessage
,
"name"
))
{
return
;
}
int
notification_id
=
NotificationId
.
getID
();
Notification
notification
=
new
NotificationCompat
.
Builder
(
this
,
channel
)
.
setSmallIcon
(
R
.
drawable
.
ic_lotusgray
)
.
setColor
(
getResources
().
getColor
(
R
.
color
.
colorPrimary
))
.
setContentTitle
(
"TEST"
)
.
setContentText
(
"TEST"
)
Notification
notification
=
standardNotificationBuilder
()
.
setContentTitle
(
remoteMessage
.
getData
().
get
(
"name"
))
.
setContentText
(
"Event is about to start"
)
.
setContentIntent
(
getNotificationIntent
(
remoteMessage
,
notification_id
))
.
setVibrate
(
new
long
[]{
0
,
400
})
.
setAutoCancel
(
true
)
.
setPriority
(
NotificationCompat
.
PRIORITY_DEFAULT
)
.
build
();
/* Show notification */
NotificationManagerCompat
notificationManager
=
NotificationManagerCompat
.
from
(
this
);
notificationManager
.
notify
(
notification_id
,
notification
);
showNotification
(
notification_id
,
notification
);
}
/** Send a standard notification from foreground */
...
...
@@ -101,19 +102,29 @@ public class InstiAppFirebaseMessagingService extends FirebaseMessagingService {
if
(
title
==
null
||
body
==
null
)
{
return
;
}
/* Build notification */
Notification
notification
=
new
NotificationCompat
.
Builder
(
this
,
channel
)
.
setSmallIcon
(
R
.
drawable
.
ic_lotusgray
)
.
setColor
(
getResources
().
getColor
(
R
.
color
.
colorPrimary
))
Notification
notification
=
standardNotificationBuilder
()
.
setContentTitle
(
title
)
.
setContentText
(
body
)
.
setContentIntent
(
getNotificationIntent
(
remoteMessage
,
notification_id
))
.
setVibrate
(
new
long
[]{
0
,
400
})
.
setAutoCancel
(
true
)
.
setPriority
(
NotificationCompat
.
PRIORITY_DEFAULT
)
.
build
();
/* Show notification */
showNotification
(
notification_id
,
notification
);
}
/** Show the notification */
private
void
showNotification
(
int
id
,
Notification
notification
)
{
NotificationManagerCompat
notificationManager
=
NotificationManagerCompat
.
from
(
this
);
notificationManager
.
notify
(
notification_id
,
notification
);
notificationManager
.
notify
(
id
,
notification
);
}
/** Common builder */
private
NotificationCompat
.
Builder
standardNotificationBuilder
()
{
return
new
NotificationCompat
.
Builder
(
this
,
channel
)
.
setSmallIcon
(
R
.
drawable
.
ic_lotusgray
)
.
setColor
(
getResources
().
getColor
(
R
.
color
.
colorPrimary
))
.
setVibrate
(
new
long
[]{
0
,
400
})
.
setAutoCancel
(
true
)
.
setPriority
(
NotificationCompat
.
PRIORITY_DEFAULT
);
}
}
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