如何在OREO之前从通知标志中删除计数?

时间:2020-02-18 14:09:47

标签: android

在奥利奥(Oreo)之前有什么方法可以删除计数数字和那个小图标或增加/减少计数数字?因为在奥利奥setBadge(false)工作之后。

我尝试了所有属性,但我认为不可能!
我已经搜索了stackoverflow和Google!但没有运气。

 @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        getToken();
        createNotification();

        int badgeCount = 11;
        ShortcutBadger.applyCount(this, badgeCount);
    }

    private void createNotification() {
        int rowId = 100;
        Uri mUri;
        int messageCount = 5;
        mUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

        String mTitle = "Dummy";
        String id = "1";

        NotificationCompat.Builder builder;
        if (mNotificationManager == null) {
            mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        }

        if (SDK_INT >= Build.VERSION_CODES.O) {
            int importance = NotificationManager.IMPORTANCE_HIGH;
            assert mNotificationManager != null;
            NotificationChannel mChannel = mNotificationManager.getNotificationChannel(id);
            if (mChannel == null) {
                mChannel = new NotificationChannel(id, mTitle, importance);
                mChannel.enableVibration(true);
                mChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
                mNotificationManager.createNotificationChannel(mChannel);
            }
            builder = new NotificationCompat.Builder(this, id);


            builder.setContentTitle(mTitle)

                    .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
                    .setContentTitle(mTitle)
                    .setSmallIcon(R.drawable.ic_audiotrack_black_24dp)
                    .setSound(mUri)
                    .setAutoCancel(true)
                    .setNumber(messageCount)
                    .setBadgeIconType(NotificationCompat.BADGE_ICON_SMALL)
                    .setCategory(NotificationCompat.CATEGORY_REMINDER)
                    .setStyle(new NotificationCompat.BigTextStyle()
                            .bigText("Have you completed your task?"))
                    .setBadgeIconType(NotificationCompat.BADGE_ICON_LARGE)
                    .addAction(R.drawable.ic_alarm_black_24dp, "pay", null);
            builder.setColor(ContextCompat.getColor(this, R.color.colorPrimary));


        } else {
            builder = new NotificationCompat.Builder(this, id);


            builder.setContentTitle(mTitle)

                    .setLargeIcon(BitmapFactory.decodeResource(this.getResources(), R.mipmap.ic_launcher))
                    .setContentTitle(mTitle)
                    .setSmallIcon(R.drawable.ic_alarm_black_24dp)
                    .setSound(mUri)
                    .setAutoCancel(true)
                    .setNumber(messageCount)
                    .setBadgeIconType(NotificationCompat.BADGE_ICON_SMALL)
                    .addAction(R.drawable.ic_alarm_black_24dp, "pay", null)
                    .setCategory(NotificationCompat.CATEGORY_REMINDER)
                    .setStyle(new NotificationCompat.BigTextStyle()
                            .bigText("Have you completed your task?"))
                    .setBadgeIconType(NotificationCompat.BADGE_ICON_LARGE)
                    .setPriority(Notification.PRIORITY_HIGH);

            builder.setColor(ContextCompat.getColor(this, R.color.colorPrimary));

            /*builder.setSubText(setTip());*/
        }

        Notification notification = builder.build();
        mNotificationManager.notify(rowId, notification);

    }

请参阅上面指定的代码版本。似乎有版本到版本更改的通知徽章。

0 个答案:

没有答案