Android O中的通知徽章 [英] Notification Badges in Android O

查看:65
本文介绍了Android O中的通知徽章的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已通过带有Android Oreo SDK的Google Nexus 5x进行了测试.即使我从应用程序中收到通知,我也无法在主屏幕的应用程序"图标中找到通知徽章,并且应用程序快捷方式未显示数字.以下是代码段:

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

推荐答案

您无法自定义应用程序启动器图标上显示的通知标志(点)的外观.但是,当您长按应用程序的启动器图标时,可以自定义长按菜单的某些元素,例如,尝试的 .setNumber(5)会显示在其中.

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.

请参考 .setBadgeIconType(R.mipmap.ic_launcher_round),建议您阅读 ** 编辑 ** (误解了问题)

我已经在Nexus 5X模拟器上测试了您的代码(没有 for 循环,仅调用一次 mNotific.notify(ncode,n); ),并且可以正常工作100%,并显示通知点.这不是与代码相关的问题.

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.

即使您可以在设备的Oreo设置中将通知点打开",Nexus 5X物理设备的本机启动器应用程序(Google即时)也不支持通知点.请参考无根像素启动器.

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.

这篇关于Android O中的通知徽章的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆