6

Im testing with Google Nexus 5x with Android Oreo SDK.I cant find Notification Badges in App icon in Homescreen,even i got notification from App And app shortcut is not showing Number.The following is snippet:

 final NotificationManager mNotific=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);

            CharSequence name="Ragav";
            String desc="this is notific";
            int imp=NotificationManager.IMPORTANCE_HIGH;
            final String ChannelID="my_channel_01";

            NotificationChannel mChannel=new NotificationChannel(ChannelID,name,imp);
            mChannel.setDescription(desc);
            mChannel.setLightColor(Color.CYAN);
            mChannel.canShowBadge();
            mChannel.setShowBadge(true);

            mNotific.createNotificationChannel(mChannel);

            final int ncode=1;

            String Body="This is testing notific";
            final Notification n= new Notification.Builder(getApplicationContext(),ChannelID)
                    .setContentTitle(getPackageName())
                    .setContentText(Body)
                    .setNumber(5)
                    .setBadgeIconType(R.mipmap.ic_launcher_round)
                    .setSmallIcon(R.mipmap.ic_launcher_round)
                    .setAutoCancel(true).build();

            for(int i=0;i<25;i++) {
                Thread.sleep(1000);
                mNotific.notify(ncode, n);
            }
Ninja
  • 678
  • 10
  • 26
Ragavendra M
  • 442
  • 5
  • 15

1 Answers1

1

You cannot customize the appearance of notification badges (dots) that appear on your app's launcher icon. You can however customize some elements of the long-press menu when you long-press your app's launcher icon, the .setNumber(5) that you tried will show up there for example.

Refer here for more insight: Notification Badges and Adjusting Notification Badges.

Referring to .setBadgeIconType(R.mipmap.ic_launcher_round), I would suggest you read this.


** EDIT ** (question misunderstood)

I have tested your code (without the for loop, calling mNotific.notify(ncode, n); only once) on a Nexus 5X emulator and it works 100% with notification dots being shown. This is not a code related issue.

The Nexus 5X physical device's native launcher app (Google Now) does not support notification dots even though you can turn notification dots "on" in Oreo Settings on the device. Refer to this and this link. To enable notification dots on a Nexus 5X physical device you'll have to install a custom Pixel Launcher app such as this Rootless Pixel Launcher.

Wess
  • 779
  • 8
  • 12
  • 2
    My issue is its not showing notification badges on app shortcut in home screen. I used " mChannel.setShowBadge(true);" to show dot on corner of icon But its not working.as i can see only app icon in homescreen. – Ragavendra M Sep 04 '17 at 06:07
  • 1
    Sorry I misunderstood your question then, "And app shortcut is not showing Number" made me think that you expected the number that you set with `.setNumber(5)` to show up on the notification badge. I have copy pasted your code without the `for` loop (calling `mNotific.notify(ncode, n)` only once) and it works 100%, a notification badge is shown. Make sure the device you are testing on is running Android Oreo, clear the data of your app (to remove all previously created Notification Channels), remove the `for` loop and `Thread.sleep(1000);` and test again, it should work. – Wess Sep 04 '17 at 07:23
  • In my application,Im using service to notify notification.The app icon is not having notification dots and when we long press the app icon,i get shortcuts like Nougat. Not like that in oreo shortcuts and the number is also not showing. i checked many times.And my device is nexus 5x with 8.0.0 version.The only thing i want is Notification Dots in App icon and when we long press icon it should show me number – Ragavendra M Sep 04 '17 at 08:40
  • Okay, I tested your code on a Nexus 5X emulator with Oreo and it works 100%. I don't think there are any problems with your code, you can verify by testing on another device. I think it is your device's launcher app not supporting notification dots. Are you using the native Nexus 5X launcher? If so, check [this link](https://www.reddit.com/r/nexus5x/comments/6fwu8m/android_o_notification_dots_with_pixel_launcher/), you have to install the Pixel launcher and manually give it permissions for notification access to enable notification dots. Let me know if it helps then I'll update the answer. – Wess Sep 04 '17 at 09:37
  • I use nexus 5x device with booted Oreo OS version in it. I also enabled notification dots allowed in app notification settings.And i had another doubt, When I use the NotificationCompat.Builder for notification object – Ragavendra M Sep 04 '17 at 09:52
  • NotificationCOmpat.Builder NotifBuild =new NotificationCompat.Builder(getBaseContext())..setContentTitle(getPackageName()) .setContentText(Body).setBadgeIconType(R.mipmap.ic_launcher) .setNumber(5) .setSmallIcon(R.mipmap.ic_launcher_round).setAutoCancel(true) .build(); --->setBadgeIconType() shows error when i enter R.mipmap.ic_launcher or BADGE_SMALL_ICON only in NotificationCompat.Builder – Ragavendra M Sep 04 '17 at 10:15
  • 1
    The Nexus 5X uses the Google Now launcher app and it does not support notification dots even though your settings may have the option, check [this link](https://productforums.google.com/forum/#!topic/nexus/f2LWAGoGZ4s) and [this link](https://productforums.google.com/d/msg/nexus/p76u94IzIpc/XJrSYjwuBAAJ) as well. "Please be informed that notification dots are only available on Pixel and Pixel XL phones. They're not available on Nexus and Pixel C devices." - I think this is clear enough. As mentioned earlier, you need to manually install the Pixel launcher app, this is not a code related issue. – Wess Sep 04 '17 at 10:15
  • is it works in emulator nexus 5x or pixel? Thanks just now i found that it wont works in nexus 5x physical device. – Ragavendra M Sep 04 '17 at 10:32
  • It does work on a Nexus 5X emulator with Oreo yes. Please check my answer, I have updated it. – Wess Sep 04 '17 at 11:30
  • how can i know if my launcher support badges? nexus6P – itzhar Oct 25 '17 at 11:12
  • The stock launcher on the Nexus 6P does not support notification dots. Some launchers that support it: Nova Launcher and the Pixel Launcher. Both of these you can get without root. – Wess Oct 25 '17 at 14:29