Notification not showing when app is in foreground in Kotlin
I am using Firebase push notification in kotlin and below are the code snippet for showing push notification
mNotifyManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
createChannel(mNotifyManager)
val mBuilder = NotificationCompat.Builder(this, "bks-channel")
.setLargeIcon(largeIcon)
.setContentTitle("Bks")
.setSmallIcon(R.drawable.app_icon)
.setContentText(message)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent)
mNotifyManager.notify(getRandomNumber(), mBuilder.build())
And the createChannel() function is :
@TargetApi(26)
private fun createChannel(notificationManager: NotificationManager)
{
val name = "bks"
val description = "bks"
val importance = NotificationManager.IMPORTANCE_DEFAULT
val mChannel = NotificationChannel(name, name, importance)
mChannel.description = description
mChannel.enableLights(true)
mChannel.lightColor = Color.BLUE
notificationManager.createNotificationChannel(mChannel)
}
Below are the server logs:
array(1) {
[9]=>
array(2) {
["name"]=>
string(14) "ABL Staff USER"
["fcm_response"]=>
array(2) {
["fields"]=>
array(3) {
["data"]=>
array(4) {
["click_action"]=>
int(2)
["title"]=>
string(19) "Attendance Reminder"
["body"]=>
string(49) "Hi ABL Staff USER, Please mark your attendance ! "
["sound"]=>
string(7) "default"
}
["registration_ids"]=>
array(11) {
[0]=>
string(152) "device_token_1"
}
["notification"]=>
array(4) {
["click_action"]=>
int(2)
["title"]=>
string(19) "Attendance Reminder"
["body"]=>
string(49) "Hi ABL Staff USER, Please mark your attendance ! "
["sound"]=>
string(7) "default"
}
}
Same are working for below android o in foreground and background but not in android o or above
android kotlin
add a comment |
I am using Firebase push notification in kotlin and below are the code snippet for showing push notification
mNotifyManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
createChannel(mNotifyManager)
val mBuilder = NotificationCompat.Builder(this, "bks-channel")
.setLargeIcon(largeIcon)
.setContentTitle("Bks")
.setSmallIcon(R.drawable.app_icon)
.setContentText(message)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent)
mNotifyManager.notify(getRandomNumber(), mBuilder.build())
And the createChannel() function is :
@TargetApi(26)
private fun createChannel(notificationManager: NotificationManager)
{
val name = "bks"
val description = "bks"
val importance = NotificationManager.IMPORTANCE_DEFAULT
val mChannel = NotificationChannel(name, name, importance)
mChannel.description = description
mChannel.enableLights(true)
mChannel.lightColor = Color.BLUE
notificationManager.createNotificationChannel(mChannel)
}
Below are the server logs:
array(1) {
[9]=>
array(2) {
["name"]=>
string(14) "ABL Staff USER"
["fcm_response"]=>
array(2) {
["fields"]=>
array(3) {
["data"]=>
array(4) {
["click_action"]=>
int(2)
["title"]=>
string(19) "Attendance Reminder"
["body"]=>
string(49) "Hi ABL Staff USER, Please mark your attendance ! "
["sound"]=>
string(7) "default"
}
["registration_ids"]=>
array(11) {
[0]=>
string(152) "device_token_1"
}
["notification"]=>
array(4) {
["click_action"]=>
int(2)
["title"]=>
string(19) "Attendance Reminder"
["body"]=>
string(49) "Hi ABL Staff USER, Please mark your attendance ! "
["sound"]=>
string(7) "default"
}
}
Same are working for below android o in foreground and background but not in android o or above
android kotlin
add a comment |
I am using Firebase push notification in kotlin and below are the code snippet for showing push notification
mNotifyManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
createChannel(mNotifyManager)
val mBuilder = NotificationCompat.Builder(this, "bks-channel")
.setLargeIcon(largeIcon)
.setContentTitle("Bks")
.setSmallIcon(R.drawable.app_icon)
.setContentText(message)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent)
mNotifyManager.notify(getRandomNumber(), mBuilder.build())
And the createChannel() function is :
@TargetApi(26)
private fun createChannel(notificationManager: NotificationManager)
{
val name = "bks"
val description = "bks"
val importance = NotificationManager.IMPORTANCE_DEFAULT
val mChannel = NotificationChannel(name, name, importance)
mChannel.description = description
mChannel.enableLights(true)
mChannel.lightColor = Color.BLUE
notificationManager.createNotificationChannel(mChannel)
}
Below are the server logs:
array(1) {
[9]=>
array(2) {
["name"]=>
string(14) "ABL Staff USER"
["fcm_response"]=>
array(2) {
["fields"]=>
array(3) {
["data"]=>
array(4) {
["click_action"]=>
int(2)
["title"]=>
string(19) "Attendance Reminder"
["body"]=>
string(49) "Hi ABL Staff USER, Please mark your attendance ! "
["sound"]=>
string(7) "default"
}
["registration_ids"]=>
array(11) {
[0]=>
string(152) "device_token_1"
}
["notification"]=>
array(4) {
["click_action"]=>
int(2)
["title"]=>
string(19) "Attendance Reminder"
["body"]=>
string(49) "Hi ABL Staff USER, Please mark your attendance ! "
["sound"]=>
string(7) "default"
}
}
Same are working for below android o in foreground and background but not in android o or above
android kotlin
I am using Firebase push notification in kotlin and below are the code snippet for showing push notification
mNotifyManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
createChannel(mNotifyManager)
val mBuilder = NotificationCompat.Builder(this, "bks-channel")
.setLargeIcon(largeIcon)
.setContentTitle("Bks")
.setSmallIcon(R.drawable.app_icon)
.setContentText(message)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent)
mNotifyManager.notify(getRandomNumber(), mBuilder.build())
And the createChannel() function is :
@TargetApi(26)
private fun createChannel(notificationManager: NotificationManager)
{
val name = "bks"
val description = "bks"
val importance = NotificationManager.IMPORTANCE_DEFAULT
val mChannel = NotificationChannel(name, name, importance)
mChannel.description = description
mChannel.enableLights(true)
mChannel.lightColor = Color.BLUE
notificationManager.createNotificationChannel(mChannel)
}
Below are the server logs:
array(1) {
[9]=>
array(2) {
["name"]=>
string(14) "ABL Staff USER"
["fcm_response"]=>
array(2) {
["fields"]=>
array(3) {
["data"]=>
array(4) {
["click_action"]=>
int(2)
["title"]=>
string(19) "Attendance Reminder"
["body"]=>
string(49) "Hi ABL Staff USER, Please mark your attendance ! "
["sound"]=>
string(7) "default"
}
["registration_ids"]=>
array(11) {
[0]=>
string(152) "device_token_1"
}
["notification"]=>
array(4) {
["click_action"]=>
int(2)
["title"]=>
string(19) "Attendance Reminder"
["body"]=>
string(49) "Hi ABL Staff USER, Please mark your attendance ! "
["sound"]=>
string(7) "default"
}
}
Same are working for below android o in foreground and background but not in android o or above
android kotlin
android kotlin
edited Nov 20 '18 at 7:04
Rakesh kushwaha
asked Nov 20 '18 at 6:26
Rakesh kushwahaRakesh kushwaha
339
339
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
FCM has sent two type of notification
- Notification Message
- Data Message
Send the data message to show a notification when the app in the background
For more details check the below link
Firebase data message
add a comment |
Are you creating channel by name "bks-channel" ? Looks like you are not creating bks-channel instead you are creating channel by name bks.
Update your create channel method.
@TargetApi(26)
private fun createChannel(notificationManager: NotificationManager) {
val name = "bks-channel"
val description = "bks"
val importance = NotificationManager.IMPORTANCE_DEFAULT
val mChannel = NotificationChannel(name, name, importance)
mChannel.description = description
mChannel.enableLights(true)
mChannel.lightColor = Color.BLUE
notificationManager.createNotificationChannel(mChannel)
}
It means channel-id and channel name will be same????
– Rakesh kushwaha
Nov 20 '18 at 7:17
channel ID has to be same but name can be anything.I mean what you pass to notification builder and the created channel ID has to be same.
– Ramesh Yankati
Nov 20 '18 at 7:31
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53387399%2fnotification-not-showing-when-app-is-in-foreground-in-kotlin%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
FCM has sent two type of notification
- Notification Message
- Data Message
Send the data message to show a notification when the app in the background
For more details check the below link
Firebase data message
add a comment |
FCM has sent two type of notification
- Notification Message
- Data Message
Send the data message to show a notification when the app in the background
For more details check the below link
Firebase data message
add a comment |
FCM has sent two type of notification
- Notification Message
- Data Message
Send the data message to show a notification when the app in the background
For more details check the below link
Firebase data message
FCM has sent two type of notification
- Notification Message
- Data Message
Send the data message to show a notification when the app in the background
For more details check the below link
Firebase data message
answered Nov 20 '18 at 6:40
JarvisJarvis
64411020
64411020
add a comment |
add a comment |
Are you creating channel by name "bks-channel" ? Looks like you are not creating bks-channel instead you are creating channel by name bks.
Update your create channel method.
@TargetApi(26)
private fun createChannel(notificationManager: NotificationManager) {
val name = "bks-channel"
val description = "bks"
val importance = NotificationManager.IMPORTANCE_DEFAULT
val mChannel = NotificationChannel(name, name, importance)
mChannel.description = description
mChannel.enableLights(true)
mChannel.lightColor = Color.BLUE
notificationManager.createNotificationChannel(mChannel)
}
It means channel-id and channel name will be same????
– Rakesh kushwaha
Nov 20 '18 at 7:17
channel ID has to be same but name can be anything.I mean what you pass to notification builder and the created channel ID has to be same.
– Ramesh Yankati
Nov 20 '18 at 7:31
add a comment |
Are you creating channel by name "bks-channel" ? Looks like you are not creating bks-channel instead you are creating channel by name bks.
Update your create channel method.
@TargetApi(26)
private fun createChannel(notificationManager: NotificationManager) {
val name = "bks-channel"
val description = "bks"
val importance = NotificationManager.IMPORTANCE_DEFAULT
val mChannel = NotificationChannel(name, name, importance)
mChannel.description = description
mChannel.enableLights(true)
mChannel.lightColor = Color.BLUE
notificationManager.createNotificationChannel(mChannel)
}
It means channel-id and channel name will be same????
– Rakesh kushwaha
Nov 20 '18 at 7:17
channel ID has to be same but name can be anything.I mean what you pass to notification builder and the created channel ID has to be same.
– Ramesh Yankati
Nov 20 '18 at 7:31
add a comment |
Are you creating channel by name "bks-channel" ? Looks like you are not creating bks-channel instead you are creating channel by name bks.
Update your create channel method.
@TargetApi(26)
private fun createChannel(notificationManager: NotificationManager) {
val name = "bks-channel"
val description = "bks"
val importance = NotificationManager.IMPORTANCE_DEFAULT
val mChannel = NotificationChannel(name, name, importance)
mChannel.description = description
mChannel.enableLights(true)
mChannel.lightColor = Color.BLUE
notificationManager.createNotificationChannel(mChannel)
}
Are you creating channel by name "bks-channel" ? Looks like you are not creating bks-channel instead you are creating channel by name bks.
Update your create channel method.
@TargetApi(26)
private fun createChannel(notificationManager: NotificationManager) {
val name = "bks-channel"
val description = "bks"
val importance = NotificationManager.IMPORTANCE_DEFAULT
val mChannel = NotificationChannel(name, name, importance)
mChannel.description = description
mChannel.enableLights(true)
mChannel.lightColor = Color.BLUE
notificationManager.createNotificationChannel(mChannel)
}
answered Nov 20 '18 at 6:58
Ramesh YankatiRamesh Yankati
65848
65848
It means channel-id and channel name will be same????
– Rakesh kushwaha
Nov 20 '18 at 7:17
channel ID has to be same but name can be anything.I mean what you pass to notification builder and the created channel ID has to be same.
– Ramesh Yankati
Nov 20 '18 at 7:31
add a comment |
It means channel-id and channel name will be same????
– Rakesh kushwaha
Nov 20 '18 at 7:17
channel ID has to be same but name can be anything.I mean what you pass to notification builder and the created channel ID has to be same.
– Ramesh Yankati
Nov 20 '18 at 7:31
It means channel-id and channel name will be same????
– Rakesh kushwaha
Nov 20 '18 at 7:17
It means channel-id and channel name will be same????
– Rakesh kushwaha
Nov 20 '18 at 7:17
channel ID has to be same but name can be anything.I mean what you pass to notification builder and the created channel ID has to be same.
– Ramesh Yankati
Nov 20 '18 at 7:31
channel ID has to be same but name can be anything.I mean what you pass to notification builder and the created channel ID has to be same.
– Ramesh Yankati
Nov 20 '18 at 7:31
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53387399%2fnotification-not-showing-when-app-is-in-foreground-in-kotlin%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown