On Android 8.1 API 27 notification does not display












25















I get Toast on Android 8.1 API 27:




Developer warning for package "my_package_name"

Failed to post notification on ...




Logcat includes next strings:




Notification: Use of stream types is deprecated for operations other
than volume control



W/Notification: See the documentation of setSound() for what to use
instead with android.media.AudioAttributes to qualify your playback
use case



E/NotificationService: No Channel found for pkg=my_package_name




The full information in the Toast and in Logcat can help in the localization this problem.










share|improve this question

























  • Post the code please

    – Samuel Robert
    Oct 28 '17 at 15:07






  • 1





    Possible duplicate of Notifications fail to display in Android Oreo (API 26)

    – Sky Kelsey
    Dec 14 '17 at 23:00











  • Related post - NotificationCompat.Builder doesn't accept 2nd argument

    – RBT
    Sep 3 '18 at 4:46
















25















I get Toast on Android 8.1 API 27:




Developer warning for package "my_package_name"

Failed to post notification on ...




Logcat includes next strings:




Notification: Use of stream types is deprecated for operations other
than volume control



W/Notification: See the documentation of setSound() for what to use
instead with android.media.AudioAttributes to qualify your playback
use case



E/NotificationService: No Channel found for pkg=my_package_name




The full information in the Toast and in Logcat can help in the localization this problem.










share|improve this question

























  • Post the code please

    – Samuel Robert
    Oct 28 '17 at 15:07






  • 1





    Possible duplicate of Notifications fail to display in Android Oreo (API 26)

    – Sky Kelsey
    Dec 14 '17 at 23:00











  • Related post - NotificationCompat.Builder doesn't accept 2nd argument

    – RBT
    Sep 3 '18 at 4:46














25












25








25


9






I get Toast on Android 8.1 API 27:




Developer warning for package "my_package_name"

Failed to post notification on ...




Logcat includes next strings:




Notification: Use of stream types is deprecated for operations other
than volume control



W/Notification: See the documentation of setSound() for what to use
instead with android.media.AudioAttributes to qualify your playback
use case



E/NotificationService: No Channel found for pkg=my_package_name




The full information in the Toast and in Logcat can help in the localization this problem.










share|improve this question
















I get Toast on Android 8.1 API 27:




Developer warning for package "my_package_name"

Failed to post notification on ...




Logcat includes next strings:




Notification: Use of stream types is deprecated for operations other
than volume control



W/Notification: See the documentation of setSound() for what to use
instead with android.media.AudioAttributes to qualify your playback
use case



E/NotificationService: No Channel found for pkg=my_package_name




The full information in the Toast and in Logcat can help in the localization this problem.







android notifications android-notifications android-8.0-oreo






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 15 '17 at 6:04







Andy Sander

















asked Oct 28 '17 at 14:50









Andy SanderAndy Sander

1,0931815




1,0931815













  • Post the code please

    – Samuel Robert
    Oct 28 '17 at 15:07






  • 1





    Possible duplicate of Notifications fail to display in Android Oreo (API 26)

    – Sky Kelsey
    Dec 14 '17 at 23:00











  • Related post - NotificationCompat.Builder doesn't accept 2nd argument

    – RBT
    Sep 3 '18 at 4:46



















  • Post the code please

    – Samuel Robert
    Oct 28 '17 at 15:07






  • 1





    Possible duplicate of Notifications fail to display in Android Oreo (API 26)

    – Sky Kelsey
    Dec 14 '17 at 23:00











  • Related post - NotificationCompat.Builder doesn't accept 2nd argument

    – RBT
    Sep 3 '18 at 4:46

















Post the code please

– Samuel Robert
Oct 28 '17 at 15:07





Post the code please

– Samuel Robert
Oct 28 '17 at 15:07




1




1





Possible duplicate of Notifications fail to display in Android Oreo (API 26)

– Sky Kelsey
Dec 14 '17 at 23:00





Possible duplicate of Notifications fail to display in Android Oreo (API 26)

– Sky Kelsey
Dec 14 '17 at 23:00













Related post - NotificationCompat.Builder doesn't accept 2nd argument

– RBT
Sep 3 '18 at 4:46





Related post - NotificationCompat.Builder doesn't accept 2nd argument

– RBT
Sep 3 '18 at 4:46












4 Answers
4






active

oldest

votes


















58














If you get this error should be paid attention to 2 items and them order:




  1. NotificationChannel mChannel = new NotificationChannel(id, name, importance);

  2. builder = new NotificationCompat.Builder(context, id);


Also NotificationManager notifManager and NotificationChannel mChannel are created only once.



There are required setters for Notification:




  • builder.setContentTitle() // required

  • .setSmallIcon() // required

  • .setContentText() // required


See example:



private NotificationManager notifManager;
public void createNotification(String aMessage, Context context) {
final int NOTIFY_ID = 0; // ID of notification
String id = context.getString(R.string.default_notification_channel_id); // default_channel_id
String title = context.getString(R.string.default_notification_channel_title); // Default Channel
Intent intent;
PendingIntent pendingIntent;
NotificationCompat.Builder builder;
if (notifManager == null) {
notifManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
int importance = NotificationManager.IMPORTANCE_HIGH;
NotificationChannel mChannel = notifManager.getNotificationChannel(id);
if (mChannel == null) {
mChannel = new NotificationChannel(id, title, importance);
mChannel.enableVibration(true);
mChannel.setVibrationPattern(new long{100, 200, 300, 400, 500, 400, 300, 200, 400});
notifManager.createNotificationChannel(mChannel);
}
builder = new NotificationCompat.Builder(context, id);
intent = new Intent(context, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
builder.setContentTitle(aMessage) // required
.setSmallIcon(android.R.drawable.ic_popup_reminder) // required
.setContentText(context.getString(R.string.app_name)) // required
.setDefaults(Notification.DEFAULT_ALL)
.setAutoCancel(true)
.setContentIntent(pendingIntent)
.setTicker(aMessage)
.setVibrate(new long{100, 200, 300, 400, 500, 400, 300, 200, 400});
}
else {
builder = new NotificationCompat.Builder(context, id);
intent = new Intent(context, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
builder.setContentTitle(aMessage) // required
.setSmallIcon(android.R.drawable.ic_popup_reminder) // required
.setContentText(context.getString(R.string.app_name)) // required
.setDefaults(Notification.DEFAULT_ALL)
.setAutoCancel(true)
.setContentIntent(pendingIntent)
.setTicker(aMessage)
.setVibrate(new long{100, 200, 300, 400, 500, 400, 300, 200, 400})
.setPriority(Notification.PRIORITY_HIGH);
}
Notification notification = builder.build();
notifManager.notify(NOTIFY_ID, notification);
}





share|improve this answer


























  • * I have set channel id, but notification still not shown; * Finally i found my problem is had not invoke "setContentText()" method * It was really help me that you mentioned "required setters"!

    – Allen
    Mar 6 '18 at 12:19








  • 1





    Thanx,it's Working!!!

    – komal akhani
    May 18 '18 at 6:54











  • Worked. Thanks a lot :)

    – Yesha
    Oct 9 '18 at 12:29











  • Working Like a charm. Thanks man.

    – sivaprakash
    Jan 9 at 11:14



















14














Andy's answer is working however I wanted to avoid to deprecated Builder and follow the FireBase Quickstart Project. I just added code before notify from manager.



String channelId = "default_channel_id";
String channelDescription = "Default Channel";
// Since android Oreo notification channel is needed.
//Check if notification channel exists and if not create one
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
NotificationChannel notificationChannel = notificationManager.getNotificationChannel(channelId);
if (notificationChannel == null) {
int importance = NotificationManager.IMPORTANCE_HIGH; //Set the importance level
notificationChannel = new NotificationChannel(channelId, channelDescription, importance);
notificationChannel.setLightColor(Color.GREEN); //Set if it is necesssary
notificationChannel.enableVibration(true); //Set if it is necesssary
notificationManager.createNotificationChannel(notificationChannel);
}
}

//notificationManager.notify as usual


Edit:
They removed the channel exist check from example I am not sure why.






share|improve this answer


























  • Thanks. Should be the accepted answer.

    – dentex
    Mar 11 '18 at 20:10



















7














I have set channel id, but notification still not shown.



Finally i found my problem is had not invoke "setContentText()" method.



It was really help me that @Andy Sander mentioned "required setters"!



here are required setters for Notification on Android 8 Oreo API 26 and later:



builder.setContentTitle() // required
.setSmallIcon() // required
.setContentText() // required
.setChannelId(id) // required for deprecated in API level >= 26 constructor .Builder(this)





share|improve this answer



















  • 1





    documentation isn't specific enough at times.

    – filthy_wizard
    Mar 6 '18 at 21:02






  • 1





    yes, it cost me lot of time. @filthy_wizard

    – Allen
    Mar 8 '18 at 3:50











  • Hello Allen,Hope you are doing great please have a look at my question stackoverflow.com/questions/50748028/…

    – user3475052
    Jun 9 '18 at 14:36





















3














Also don't forget to bind your channel_id to your notification builder. After binding it, my problem gone.



notificationBuilder.setChannelId(channelId)


or



NotificationCompat.Builder(Context context, String channelId)





share|improve this answer





















  • 2





    stackoverflow.com/questions/45462666/…

    – Andy Sander
    Aug 2 '18 at 19:14











  • Should only use second method

    – barnacle.m
    Nov 21 '18 at 12:10











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
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f46990995%2fon-android-8-1-api-27-notification-does-not-display%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























4 Answers
4






active

oldest

votes








4 Answers
4






active

oldest

votes









active

oldest

votes






active

oldest

votes









58














If you get this error should be paid attention to 2 items and them order:




  1. NotificationChannel mChannel = new NotificationChannel(id, name, importance);

  2. builder = new NotificationCompat.Builder(context, id);


Also NotificationManager notifManager and NotificationChannel mChannel are created only once.



There are required setters for Notification:




  • builder.setContentTitle() // required

  • .setSmallIcon() // required

  • .setContentText() // required


See example:



private NotificationManager notifManager;
public void createNotification(String aMessage, Context context) {
final int NOTIFY_ID = 0; // ID of notification
String id = context.getString(R.string.default_notification_channel_id); // default_channel_id
String title = context.getString(R.string.default_notification_channel_title); // Default Channel
Intent intent;
PendingIntent pendingIntent;
NotificationCompat.Builder builder;
if (notifManager == null) {
notifManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
int importance = NotificationManager.IMPORTANCE_HIGH;
NotificationChannel mChannel = notifManager.getNotificationChannel(id);
if (mChannel == null) {
mChannel = new NotificationChannel(id, title, importance);
mChannel.enableVibration(true);
mChannel.setVibrationPattern(new long{100, 200, 300, 400, 500, 400, 300, 200, 400});
notifManager.createNotificationChannel(mChannel);
}
builder = new NotificationCompat.Builder(context, id);
intent = new Intent(context, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
builder.setContentTitle(aMessage) // required
.setSmallIcon(android.R.drawable.ic_popup_reminder) // required
.setContentText(context.getString(R.string.app_name)) // required
.setDefaults(Notification.DEFAULT_ALL)
.setAutoCancel(true)
.setContentIntent(pendingIntent)
.setTicker(aMessage)
.setVibrate(new long{100, 200, 300, 400, 500, 400, 300, 200, 400});
}
else {
builder = new NotificationCompat.Builder(context, id);
intent = new Intent(context, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
builder.setContentTitle(aMessage) // required
.setSmallIcon(android.R.drawable.ic_popup_reminder) // required
.setContentText(context.getString(R.string.app_name)) // required
.setDefaults(Notification.DEFAULT_ALL)
.setAutoCancel(true)
.setContentIntent(pendingIntent)
.setTicker(aMessage)
.setVibrate(new long{100, 200, 300, 400, 500, 400, 300, 200, 400})
.setPriority(Notification.PRIORITY_HIGH);
}
Notification notification = builder.build();
notifManager.notify(NOTIFY_ID, notification);
}





share|improve this answer


























  • * I have set channel id, but notification still not shown; * Finally i found my problem is had not invoke "setContentText()" method * It was really help me that you mentioned "required setters"!

    – Allen
    Mar 6 '18 at 12:19








  • 1





    Thanx,it's Working!!!

    – komal akhani
    May 18 '18 at 6:54











  • Worked. Thanks a lot :)

    – Yesha
    Oct 9 '18 at 12:29











  • Working Like a charm. Thanks man.

    – sivaprakash
    Jan 9 at 11:14
















58














If you get this error should be paid attention to 2 items and them order:




  1. NotificationChannel mChannel = new NotificationChannel(id, name, importance);

  2. builder = new NotificationCompat.Builder(context, id);


Also NotificationManager notifManager and NotificationChannel mChannel are created only once.



There are required setters for Notification:




  • builder.setContentTitle() // required

  • .setSmallIcon() // required

  • .setContentText() // required


See example:



private NotificationManager notifManager;
public void createNotification(String aMessage, Context context) {
final int NOTIFY_ID = 0; // ID of notification
String id = context.getString(R.string.default_notification_channel_id); // default_channel_id
String title = context.getString(R.string.default_notification_channel_title); // Default Channel
Intent intent;
PendingIntent pendingIntent;
NotificationCompat.Builder builder;
if (notifManager == null) {
notifManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
int importance = NotificationManager.IMPORTANCE_HIGH;
NotificationChannel mChannel = notifManager.getNotificationChannel(id);
if (mChannel == null) {
mChannel = new NotificationChannel(id, title, importance);
mChannel.enableVibration(true);
mChannel.setVibrationPattern(new long{100, 200, 300, 400, 500, 400, 300, 200, 400});
notifManager.createNotificationChannel(mChannel);
}
builder = new NotificationCompat.Builder(context, id);
intent = new Intent(context, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
builder.setContentTitle(aMessage) // required
.setSmallIcon(android.R.drawable.ic_popup_reminder) // required
.setContentText(context.getString(R.string.app_name)) // required
.setDefaults(Notification.DEFAULT_ALL)
.setAutoCancel(true)
.setContentIntent(pendingIntent)
.setTicker(aMessage)
.setVibrate(new long{100, 200, 300, 400, 500, 400, 300, 200, 400});
}
else {
builder = new NotificationCompat.Builder(context, id);
intent = new Intent(context, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
builder.setContentTitle(aMessage) // required
.setSmallIcon(android.R.drawable.ic_popup_reminder) // required
.setContentText(context.getString(R.string.app_name)) // required
.setDefaults(Notification.DEFAULT_ALL)
.setAutoCancel(true)
.setContentIntent(pendingIntent)
.setTicker(aMessage)
.setVibrate(new long{100, 200, 300, 400, 500, 400, 300, 200, 400})
.setPriority(Notification.PRIORITY_HIGH);
}
Notification notification = builder.build();
notifManager.notify(NOTIFY_ID, notification);
}





share|improve this answer


























  • * I have set channel id, but notification still not shown; * Finally i found my problem is had not invoke "setContentText()" method * It was really help me that you mentioned "required setters"!

    – Allen
    Mar 6 '18 at 12:19








  • 1





    Thanx,it's Working!!!

    – komal akhani
    May 18 '18 at 6:54











  • Worked. Thanks a lot :)

    – Yesha
    Oct 9 '18 at 12:29











  • Working Like a charm. Thanks man.

    – sivaprakash
    Jan 9 at 11:14














58












58








58







If you get this error should be paid attention to 2 items and them order:




  1. NotificationChannel mChannel = new NotificationChannel(id, name, importance);

  2. builder = new NotificationCompat.Builder(context, id);


Also NotificationManager notifManager and NotificationChannel mChannel are created only once.



There are required setters for Notification:




  • builder.setContentTitle() // required

  • .setSmallIcon() // required

  • .setContentText() // required


See example:



private NotificationManager notifManager;
public void createNotification(String aMessage, Context context) {
final int NOTIFY_ID = 0; // ID of notification
String id = context.getString(R.string.default_notification_channel_id); // default_channel_id
String title = context.getString(R.string.default_notification_channel_title); // Default Channel
Intent intent;
PendingIntent pendingIntent;
NotificationCompat.Builder builder;
if (notifManager == null) {
notifManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
int importance = NotificationManager.IMPORTANCE_HIGH;
NotificationChannel mChannel = notifManager.getNotificationChannel(id);
if (mChannel == null) {
mChannel = new NotificationChannel(id, title, importance);
mChannel.enableVibration(true);
mChannel.setVibrationPattern(new long{100, 200, 300, 400, 500, 400, 300, 200, 400});
notifManager.createNotificationChannel(mChannel);
}
builder = new NotificationCompat.Builder(context, id);
intent = new Intent(context, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
builder.setContentTitle(aMessage) // required
.setSmallIcon(android.R.drawable.ic_popup_reminder) // required
.setContentText(context.getString(R.string.app_name)) // required
.setDefaults(Notification.DEFAULT_ALL)
.setAutoCancel(true)
.setContentIntent(pendingIntent)
.setTicker(aMessage)
.setVibrate(new long{100, 200, 300, 400, 500, 400, 300, 200, 400});
}
else {
builder = new NotificationCompat.Builder(context, id);
intent = new Intent(context, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
builder.setContentTitle(aMessage) // required
.setSmallIcon(android.R.drawable.ic_popup_reminder) // required
.setContentText(context.getString(R.string.app_name)) // required
.setDefaults(Notification.DEFAULT_ALL)
.setAutoCancel(true)
.setContentIntent(pendingIntent)
.setTicker(aMessage)
.setVibrate(new long{100, 200, 300, 400, 500, 400, 300, 200, 400})
.setPriority(Notification.PRIORITY_HIGH);
}
Notification notification = builder.build();
notifManager.notify(NOTIFY_ID, notification);
}





share|improve this answer















If you get this error should be paid attention to 2 items and them order:




  1. NotificationChannel mChannel = new NotificationChannel(id, name, importance);

  2. builder = new NotificationCompat.Builder(context, id);


Also NotificationManager notifManager and NotificationChannel mChannel are created only once.



There are required setters for Notification:




  • builder.setContentTitle() // required

  • .setSmallIcon() // required

  • .setContentText() // required


See example:



private NotificationManager notifManager;
public void createNotification(String aMessage, Context context) {
final int NOTIFY_ID = 0; // ID of notification
String id = context.getString(R.string.default_notification_channel_id); // default_channel_id
String title = context.getString(R.string.default_notification_channel_title); // Default Channel
Intent intent;
PendingIntent pendingIntent;
NotificationCompat.Builder builder;
if (notifManager == null) {
notifManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
int importance = NotificationManager.IMPORTANCE_HIGH;
NotificationChannel mChannel = notifManager.getNotificationChannel(id);
if (mChannel == null) {
mChannel = new NotificationChannel(id, title, importance);
mChannel.enableVibration(true);
mChannel.setVibrationPattern(new long{100, 200, 300, 400, 500, 400, 300, 200, 400});
notifManager.createNotificationChannel(mChannel);
}
builder = new NotificationCompat.Builder(context, id);
intent = new Intent(context, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
builder.setContentTitle(aMessage) // required
.setSmallIcon(android.R.drawable.ic_popup_reminder) // required
.setContentText(context.getString(R.string.app_name)) // required
.setDefaults(Notification.DEFAULT_ALL)
.setAutoCancel(true)
.setContentIntent(pendingIntent)
.setTicker(aMessage)
.setVibrate(new long{100, 200, 300, 400, 500, 400, 300, 200, 400});
}
else {
builder = new NotificationCompat.Builder(context, id);
intent = new Intent(context, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
builder.setContentTitle(aMessage) // required
.setSmallIcon(android.R.drawable.ic_popup_reminder) // required
.setContentText(context.getString(R.string.app_name)) // required
.setDefaults(Notification.DEFAULT_ALL)
.setAutoCancel(true)
.setContentIntent(pendingIntent)
.setTicker(aMessage)
.setVibrate(new long{100, 200, 300, 400, 500, 400, 300, 200, 400})
.setPriority(Notification.PRIORITY_HIGH);
}
Notification notification = builder.build();
notifManager.notify(NOTIFY_ID, notification);
}






share|improve this answer














share|improve this answer



share|improve this answer








edited Sep 16 '18 at 12:23

























answered Oct 28 '17 at 15:14









Andy SanderAndy Sander

1,0931815




1,0931815













  • * I have set channel id, but notification still not shown; * Finally i found my problem is had not invoke "setContentText()" method * It was really help me that you mentioned "required setters"!

    – Allen
    Mar 6 '18 at 12:19








  • 1





    Thanx,it's Working!!!

    – komal akhani
    May 18 '18 at 6:54











  • Worked. Thanks a lot :)

    – Yesha
    Oct 9 '18 at 12:29











  • Working Like a charm. Thanks man.

    – sivaprakash
    Jan 9 at 11:14



















  • * I have set channel id, but notification still not shown; * Finally i found my problem is had not invoke "setContentText()" method * It was really help me that you mentioned "required setters"!

    – Allen
    Mar 6 '18 at 12:19








  • 1





    Thanx,it's Working!!!

    – komal akhani
    May 18 '18 at 6:54











  • Worked. Thanks a lot :)

    – Yesha
    Oct 9 '18 at 12:29











  • Working Like a charm. Thanks man.

    – sivaprakash
    Jan 9 at 11:14

















* I have set channel id, but notification still not shown; * Finally i found my problem is had not invoke "setContentText()" method * It was really help me that you mentioned "required setters"!

– Allen
Mar 6 '18 at 12:19







* I have set channel id, but notification still not shown; * Finally i found my problem is had not invoke "setContentText()" method * It was really help me that you mentioned "required setters"!

– Allen
Mar 6 '18 at 12:19






1




1





Thanx,it's Working!!!

– komal akhani
May 18 '18 at 6:54





Thanx,it's Working!!!

– komal akhani
May 18 '18 at 6:54













Worked. Thanks a lot :)

– Yesha
Oct 9 '18 at 12:29





Worked. Thanks a lot :)

– Yesha
Oct 9 '18 at 12:29













Working Like a charm. Thanks man.

– sivaprakash
Jan 9 at 11:14





Working Like a charm. Thanks man.

– sivaprakash
Jan 9 at 11:14













14














Andy's answer is working however I wanted to avoid to deprecated Builder and follow the FireBase Quickstart Project. I just added code before notify from manager.



String channelId = "default_channel_id";
String channelDescription = "Default Channel";
// Since android Oreo notification channel is needed.
//Check if notification channel exists and if not create one
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
NotificationChannel notificationChannel = notificationManager.getNotificationChannel(channelId);
if (notificationChannel == null) {
int importance = NotificationManager.IMPORTANCE_HIGH; //Set the importance level
notificationChannel = new NotificationChannel(channelId, channelDescription, importance);
notificationChannel.setLightColor(Color.GREEN); //Set if it is necesssary
notificationChannel.enableVibration(true); //Set if it is necesssary
notificationManager.createNotificationChannel(notificationChannel);
}
}

//notificationManager.notify as usual


Edit:
They removed the channel exist check from example I am not sure why.






share|improve this answer


























  • Thanks. Should be the accepted answer.

    – dentex
    Mar 11 '18 at 20:10
















14














Andy's answer is working however I wanted to avoid to deprecated Builder and follow the FireBase Quickstart Project. I just added code before notify from manager.



String channelId = "default_channel_id";
String channelDescription = "Default Channel";
// Since android Oreo notification channel is needed.
//Check if notification channel exists and if not create one
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
NotificationChannel notificationChannel = notificationManager.getNotificationChannel(channelId);
if (notificationChannel == null) {
int importance = NotificationManager.IMPORTANCE_HIGH; //Set the importance level
notificationChannel = new NotificationChannel(channelId, channelDescription, importance);
notificationChannel.setLightColor(Color.GREEN); //Set if it is necesssary
notificationChannel.enableVibration(true); //Set if it is necesssary
notificationManager.createNotificationChannel(notificationChannel);
}
}

//notificationManager.notify as usual


Edit:
They removed the channel exist check from example I am not sure why.






share|improve this answer


























  • Thanks. Should be the accepted answer.

    – dentex
    Mar 11 '18 at 20:10














14












14








14







Andy's answer is working however I wanted to avoid to deprecated Builder and follow the FireBase Quickstart Project. I just added code before notify from manager.



String channelId = "default_channel_id";
String channelDescription = "Default Channel";
// Since android Oreo notification channel is needed.
//Check if notification channel exists and if not create one
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
NotificationChannel notificationChannel = notificationManager.getNotificationChannel(channelId);
if (notificationChannel == null) {
int importance = NotificationManager.IMPORTANCE_HIGH; //Set the importance level
notificationChannel = new NotificationChannel(channelId, channelDescription, importance);
notificationChannel.setLightColor(Color.GREEN); //Set if it is necesssary
notificationChannel.enableVibration(true); //Set if it is necesssary
notificationManager.createNotificationChannel(notificationChannel);
}
}

//notificationManager.notify as usual


Edit:
They removed the channel exist check from example I am not sure why.






share|improve this answer















Andy's answer is working however I wanted to avoid to deprecated Builder and follow the FireBase Quickstart Project. I just added code before notify from manager.



String channelId = "default_channel_id";
String channelDescription = "Default Channel";
// Since android Oreo notification channel is needed.
//Check if notification channel exists and if not create one
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
NotificationChannel notificationChannel = notificationManager.getNotificationChannel(channelId);
if (notificationChannel == null) {
int importance = NotificationManager.IMPORTANCE_HIGH; //Set the importance level
notificationChannel = new NotificationChannel(channelId, channelDescription, importance);
notificationChannel.setLightColor(Color.GREEN); //Set if it is necesssary
notificationChannel.enableVibration(true); //Set if it is necesssary
notificationManager.createNotificationChannel(notificationChannel);
}
}

//notificationManager.notify as usual


Edit:
They removed the channel exist check from example I am not sure why.







share|improve this answer














share|improve this answer



share|improve this answer








edited Oct 30 '18 at 11:14

























answered Dec 18 '17 at 14:10









engincancanengincancan

1,49111938




1,49111938













  • Thanks. Should be the accepted answer.

    – dentex
    Mar 11 '18 at 20:10



















  • Thanks. Should be the accepted answer.

    – dentex
    Mar 11 '18 at 20:10

















Thanks. Should be the accepted answer.

– dentex
Mar 11 '18 at 20:10





Thanks. Should be the accepted answer.

– dentex
Mar 11 '18 at 20:10











7














I have set channel id, but notification still not shown.



Finally i found my problem is had not invoke "setContentText()" method.



It was really help me that @Andy Sander mentioned "required setters"!



here are required setters for Notification on Android 8 Oreo API 26 and later:



builder.setContentTitle() // required
.setSmallIcon() // required
.setContentText() // required
.setChannelId(id) // required for deprecated in API level >= 26 constructor .Builder(this)





share|improve this answer



















  • 1





    documentation isn't specific enough at times.

    – filthy_wizard
    Mar 6 '18 at 21:02






  • 1





    yes, it cost me lot of time. @filthy_wizard

    – Allen
    Mar 8 '18 at 3:50











  • Hello Allen,Hope you are doing great please have a look at my question stackoverflow.com/questions/50748028/…

    – user3475052
    Jun 9 '18 at 14:36


















7














I have set channel id, but notification still not shown.



Finally i found my problem is had not invoke "setContentText()" method.



It was really help me that @Andy Sander mentioned "required setters"!



here are required setters for Notification on Android 8 Oreo API 26 and later:



builder.setContentTitle() // required
.setSmallIcon() // required
.setContentText() // required
.setChannelId(id) // required for deprecated in API level >= 26 constructor .Builder(this)





share|improve this answer



















  • 1





    documentation isn't specific enough at times.

    – filthy_wizard
    Mar 6 '18 at 21:02






  • 1





    yes, it cost me lot of time. @filthy_wizard

    – Allen
    Mar 8 '18 at 3:50











  • Hello Allen,Hope you are doing great please have a look at my question stackoverflow.com/questions/50748028/…

    – user3475052
    Jun 9 '18 at 14:36
















7












7








7







I have set channel id, but notification still not shown.



Finally i found my problem is had not invoke "setContentText()" method.



It was really help me that @Andy Sander mentioned "required setters"!



here are required setters for Notification on Android 8 Oreo API 26 and later:



builder.setContentTitle() // required
.setSmallIcon() // required
.setContentText() // required
.setChannelId(id) // required for deprecated in API level >= 26 constructor .Builder(this)





share|improve this answer













I have set channel id, but notification still not shown.



Finally i found my problem is had not invoke "setContentText()" method.



It was really help me that @Andy Sander mentioned "required setters"!



here are required setters for Notification on Android 8 Oreo API 26 and later:



builder.setContentTitle() // required
.setSmallIcon() // required
.setContentText() // required
.setChannelId(id) // required for deprecated in API level >= 26 constructor .Builder(this)






share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 6 '18 at 12:23









AllenAllen

769812




769812








  • 1





    documentation isn't specific enough at times.

    – filthy_wizard
    Mar 6 '18 at 21:02






  • 1





    yes, it cost me lot of time. @filthy_wizard

    – Allen
    Mar 8 '18 at 3:50











  • Hello Allen,Hope you are doing great please have a look at my question stackoverflow.com/questions/50748028/…

    – user3475052
    Jun 9 '18 at 14:36
















  • 1





    documentation isn't specific enough at times.

    – filthy_wizard
    Mar 6 '18 at 21:02






  • 1





    yes, it cost me lot of time. @filthy_wizard

    – Allen
    Mar 8 '18 at 3:50











  • Hello Allen,Hope you are doing great please have a look at my question stackoverflow.com/questions/50748028/…

    – user3475052
    Jun 9 '18 at 14:36










1




1





documentation isn't specific enough at times.

– filthy_wizard
Mar 6 '18 at 21:02





documentation isn't specific enough at times.

– filthy_wizard
Mar 6 '18 at 21:02




1




1





yes, it cost me lot of time. @filthy_wizard

– Allen
Mar 8 '18 at 3:50





yes, it cost me lot of time. @filthy_wizard

– Allen
Mar 8 '18 at 3:50













Hello Allen,Hope you are doing great please have a look at my question stackoverflow.com/questions/50748028/…

– user3475052
Jun 9 '18 at 14:36







Hello Allen,Hope you are doing great please have a look at my question stackoverflow.com/questions/50748028/…

– user3475052
Jun 9 '18 at 14:36













3














Also don't forget to bind your channel_id to your notification builder. After binding it, my problem gone.



notificationBuilder.setChannelId(channelId)


or



NotificationCompat.Builder(Context context, String channelId)





share|improve this answer





















  • 2





    stackoverflow.com/questions/45462666/…

    – Andy Sander
    Aug 2 '18 at 19:14











  • Should only use second method

    – barnacle.m
    Nov 21 '18 at 12:10
















3














Also don't forget to bind your channel_id to your notification builder. After binding it, my problem gone.



notificationBuilder.setChannelId(channelId)


or



NotificationCompat.Builder(Context context, String channelId)





share|improve this answer





















  • 2





    stackoverflow.com/questions/45462666/…

    – Andy Sander
    Aug 2 '18 at 19:14











  • Should only use second method

    – barnacle.m
    Nov 21 '18 at 12:10














3












3








3







Also don't forget to bind your channel_id to your notification builder. After binding it, my problem gone.



notificationBuilder.setChannelId(channelId)


or



NotificationCompat.Builder(Context context, String channelId)





share|improve this answer















Also don't forget to bind your channel_id to your notification builder. After binding it, my problem gone.



notificationBuilder.setChannelId(channelId)


or



NotificationCompat.Builder(Context context, String channelId)






share|improve this answer














share|improve this answer



share|improve this answer








edited Aug 6 '18 at 20:25

























answered Jul 31 '18 at 19:39









asozcanasozcan

9051018




9051018








  • 2





    stackoverflow.com/questions/45462666/…

    – Andy Sander
    Aug 2 '18 at 19:14











  • Should only use second method

    – barnacle.m
    Nov 21 '18 at 12:10














  • 2





    stackoverflow.com/questions/45462666/…

    – Andy Sander
    Aug 2 '18 at 19:14











  • Should only use second method

    – barnacle.m
    Nov 21 '18 at 12:10








2




2





stackoverflow.com/questions/45462666/…

– Andy Sander
Aug 2 '18 at 19:14





stackoverflow.com/questions/45462666/…

– Andy Sander
Aug 2 '18 at 19:14













Should only use second method

– barnacle.m
Nov 21 '18 at 12:10





Should only use second method

– barnacle.m
Nov 21 '18 at 12:10


















draft saved

draft discarded




















































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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f46990995%2fon-android-8-1-api-27-notification-does-not-display%23new-answer', 'question_page');
}
);

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







Popular posts from this blog

Mossoró

Error while reading .h5 file using the rhdf5 package in R

Pushsharp Apns notification error: 'InvalidToken'