Android O 中的通知徽章

2024-01-04

我正在使用 Android Oreo SDK 使用 Google Nexus 5x 进行测试。我无法在主屏幕的应用程序图标中找到通知徽章,即使我收到来自应用程序的通知,并且应用程序快捷方式未显示数字。以下是代码片段:

 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)例如,您尝试过的内容会显示在那里。

请参阅此处了解更多见解:通知徽章 https://developer.android.com/guide/topics/ui/notifiers/notifications.html#Badges and 调整通知徽章 https://developer.android.com/guide/topics/ui/notifiers/notifications.html#AdjustingBadges.

参考.setBadgeIconType(R.mipmap.ic_launcher_round),我建议你阅读this https://developer.android.com/reference/android/app/Notification.Builder.html#setBadgeIconType(int).


** EDIT ** (问题被误解了)

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

Nexus 5X 物理设备的本机启动器应用程序 (Google Now) 不支持通知点,即使您可以在设备上的 Oreo 设置中“打开”通知点。参考this https://productforums.google.com/forum/#!topic/nexus/f2LWAGoGZ4s and this https://productforums.google.com/forum/#!msg/nexus/p76u94IzIpc/XJrSYjwuBAAJ关联。要在 Nexus 5X 物理设备上启用通知点,您必须安装自定义 Pixel Launcher 应用程序,如下所示无根像素启动器 https://github.com/amirzaidi/Launcher3/releases.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Android O 中的通知徽章 的相关文章

随机推荐