Android O中的通知徽章

时间:2017-09-01 12:41:02

标签: android badge shortcuts android-8.0-oreo

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

 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 个答案:

答案 0 :(得分:1)

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

请参阅此处以获取更多信息:Notification BadgesAdjusting Notification Badges

参考.setBadgeIconType(R.mipmap.ic_launcher_round),我建议您阅读this

** 编辑 ** (问题被误解)

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

Nexus 5X物理设备的原生启动器应用程序(Google即时版)不支持通知点,即使您可以转动通知点&#34; on&#34;在设备上的Oreo设置中。请参阅thisthis链接。要在Nexus 5X物理设备上启用通知点,您必须安装自定义Pixel Launcher应用,例如Rootless Pixel Launcher

相关问题