如何在Oreo中的应用程序图标上显示通知计数徽章?

时间:2019-03-27 03:39:34

标签: android android-8.0-oreo

我收到Oreo版本的通知。但是我需要在应用程序图标上显示计数徽章。我无法显示计数徽章。请帮助

先谢谢了:)

获取通知的功能

public void sendOnChannel1(View v){
            String title = editTextTitle.getText().toString();
            String messagge = editTextMessage.getText().toString();
            Notification notification = new NotificationCompat.Builder(this,CHANNEL_1_ID)
                    .setSmallIcon(R.drawable.ic_one)
                    .setContentTitle(title)
                    .setContentText(messagge)
                    .setPriority(NotificationCompat.PRIORITY_HIGH)
                    .setCategory(NotificationCompat.CATEGORY_MESSAGE)
                    .setNumber(3)

                    .setBadgeIconType(NotificationCompat.BADGE_ICON_SMALL)
                    .build();


            notificationManager.notify(1, notification);
    }

此功能用于创建通知频道

 private void createNotificationChannels() {
            if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.O){
                try{
                    NotificationChannel channel1=new NotificationChannel(CHANNEL_1_ID, "Channel 1", NotificationManager.IMPORTANCE_HIGH);
                    channel1.setDescription("This is Channel 1");
                    channel1.setShowBadge(true);
                    channel1.canShowBadge();
                    NotificationManager manager=getSystemService(NotificationManager.class);
                    manager.createNotificationChannel(channel1);
                }
                catch (Exception e){
                    e.printStackTrace();
                }

            }
        }

我想在应用程序图标上显示计数徽章

0 个答案:

没有答案