Android 11 设备未显示徽章计数

问题描述

我正在展示一个 Android 应用,以在应用启动器图标上显示徽章计数。在不同的版本中尝试过,但它在 Android 11 上不起作用。我可以知道,在 android 11 上有什么新的 API 吗?

我使用的代码如下:

 scheduleNotification(getNotification( "Submitted Successfully" ),100 ) ;

  private Notification getNotification (String content) {
        NotificationCompat.Builder builder = new NotificationCompat.Builder( this,default_notification_channel_id ) ;
        builder.setContentTitle( "Notification" ) ;
        builder.setContentText(content) ;
        builder.setSmallIcon(R.drawable. ic_launcher_foreground ) ;
        builder.setAutoCancel( true ) ;
        builder.setChannelId( NOTIFICATION_CHANNEL_ID ) ;
        builder.setNumber(8);
        writeLog("Home Screen -->"+ Thread.currentThread().getStackTrace()[1].
                getLineNumber()+" --> Offline Submission Locally Notified ");

        return builder.build() ;
    }

private void scheduleNotification (Notification notification,int delay) {
        Intent notificationIntent = new Intent( this,MyNotificationPublisher. class ) ;
        notificationIntent.putExtra(MyNotificationPublisher. NOTIFICATION_ID,1 ) ;
        notificationIntent.putExtra(MyNotificationPublisher. NOTIFICATION,notification) ;
        PendingIntent pendingIntent = PendingIntent. getbroadcast ( this,notificationIntent,PendingIntent. FLAG_UPDATE_CURRENT ) ;
        long futureInMillis = SystemClock. elapsedRealtime () + delay ;
        AlarmManager alarmManager = (AlarmManager) getSystemService(Context. ALARM_SERVICE ) ;
        assert alarmManager != null;
        alarmManager.set(AlarmManager. ELAPSED_REALTIME_WAKEUP,futureInMillis,pendingIntent) ;
      
    }

MyNotificationPublisher 类看起来:

public class MyNotificationPublisher extends broadcastReceiver {
    public static String NOTIFICATION_ID = "notification-id" ;
    public static String NOTIFICATION = "notification" ;
    public static String NOTIFICATION_CHANNEL_ID ="10001";
    public void onReceive (Context context,Intent intent) {
        notificationmanager notificationmanager = (notificationmanager)context.getSystemService(Context. NOTIFICATION_SERVICE ) ;
        Notification notification = intent.getParcelableExtra( NOTIFICATION ) ;
        if (android.os.Build.VERSION. SDK_INT >= android.os.Build.VERSION_CODES. O ) {
            int importance = notificationmanager. IMPORTANCE_HIGH ;
            NotificationChannel notificationChannel = new NotificationChannel( NOTIFICATION_CHANNEL_ID,"NOTIFICATION_CHANNEL_NAME",importance) ;
            assert notificationmanager != null;
            notificationmanager.createNotificationChannel(notificationChannel) ;
        }
        int id = intent.getIntExtra( NOTIFICATION_ID,0 ) ;
        assert notificationmanager != null;
        notificationmanager.notify(id,notification) ;
    }
}

解决方法

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

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

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