如何解决如何在android10三星设备中使用java更改badge-icon-number
测试结果:
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 举报,一经查实,本站将立刻删除。