Notification Badges in Android O

╄→гoц情女王★ 提交于 2021-02-18 12:00:11

问题


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

回答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.



来源:https://stackoverflow.com/questions/46000499/notification-badges-in-android-o

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!