Home Android Notification Not Showing On API 26 oreo version Notification
Reply: 0

Android Notification Not Showing On API 26 oreo version Notification

Eloa Barretto
Eloa Barretto Published in 2017-12-07 04:48:43Z

This question already has an answer here:

  • Notification not showing in Android 8 Oreo 3 answers
  • How to create a Android notification with support to older API levels (e.g. lvl 23) 1 answer

I want to make this code work in api 26 but I can not ..

Anyone know how to adapt to android 8?

Lint in Android Studio is showing a deprecated warning for the follow notification builder method:

new NotificationCompat.Builder(context)

The problem is: Android Developers update his Documentation describing NotificationChannel to support notifications in Android O, and provide us with a snippet, yet with the same deprecated warning:

 NotificationCompat.Builder  mBuilder;

public void gerarNotificacao(Context context, Intent intent, CharSequence ticker, CharSequence titulo, CharSequence descricao) {
        NotificationManager nm = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
        PendingIntent p = PendingIntent.getActivity(context, 0, intent, 0);
        if (Build.VERSION.SDK_INT >= 26) {
           mBuilder = new NotificationCompat.Builder(context, "My Notifications");
        } else {
            mBuilder = new NotificationCompat.Builder(context);
            mBuilder.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher));
            Notification n = mBuilder.build();
            // Set the notification vibrate option
            if (preferences.getBoolean("notifications_new_message_vibrate", true)) {
                n.vibrate = new long[]{150, 300, 150, 600};
            n.flags = Notification.FLAG_AUTO_CANCEL;
            // Set the notification ringtone
            if (preferences.getString("notifications_new_message_ringtone", null) != null) {
                mBuilder.setSound(Uri.parse(preferences.getString("notifications_new_message_ringtone", null)));
            } else {
                Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

            // Show only if the notification are enabled
            if (preferences.getBoolean("notifications_new_message", true)) {
                //nm.notify(NOTIFICATION_ID, mBuilder.build());
                nm.notify(R.mipmap.ic_launcher, n);

works perfectly up to android 7.1

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.311227 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO