如何在android10三星设备中使用java更改badge-icon-number

问题描述

wrong number of badge here

测试结果:

I tried to set the badge-number to '88' !!
But badge-number always shows '63',not changed  in the device of Android10 samsung!! 

代码

void showNotification(String title,String message,int messageCount) {
    
     notificationmanager mnotificationmanager =
            (notificationmanager) mcxt.getSystemService(Context.NOTIFICATION_SERVICE);

    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
        NotificationChannel channel = new NotificationChannel("YOUR_CHANNEL_ID","YOUR_CHANNEL_NAME",notificationmanager.IMPORTANCE_DEFAULT);
        channel.setDescription("YOUR_NOTIFICATION_CHANNEL_DESCRIPTION");
        channel.setShowBadge(true);
        mnotificationmanager.createNotificationChannel(channel);
    }
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mcxt,"YOUR_CHANNEL_ID")
            .setSmallIcon(R.mipmap.ic_launcher_foreground) // notification icon
            .setContentTitle(title) // title for notification
            .setContentText(message)// message for notification
            .setStyle(new NotificationCompat.BigTextStyle().bigText(message))
            //.setBadgeIconType(NotificationCompat.BADGE_ICON_LARGE)
            .setBadgeIconType(NotificationCompat.BADGE_ICON_SMALL)
            .setNumber(88)
            .setShowWhen(true)
            .setAutoCancel(true); // clear notification after click



    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    intent.setComponent(new ComponentName(mcxt,MainActivity.class));
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);

    PendingIntent pi = PendingIntent.getActivity(mcxt,1,intent,PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(pi);
    mnotificationmanager.notify(1,mBuilder.build());

}

// ------------------------------------------

问题代码:setNumber(88)

// ------------------------------------------

无法正常运行的设备:android 10三星银河a30
// ------------------------------------------

良好的工作设备:android 8三星银河note3,lg Q6

// ------------------------------------------

仅在我的设备上是错误的? -..-;

// ------------------------------------------

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)