此问题可能与Android 12的新权限政策有关。您需要确保在Android 12及以上版本中正确设置了通知渠道。
以下是示例代码,可在Android 12及以上版本中设置通知渠道:
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { // Create the NotificationChannel val name = getString(R.string.channel_name) val descriptionText = getString(R.string.channel_description) val importance = NotificationManager.IMPORTANCE_DEFAULT val channel = NotificationChannel(CHANNEL_ID, name, importance).apply { description = descriptionText } // Register the channel with the system val notificationManager: NotificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager notificationManager.createNotificationChannel(channel) }
您需要将上述代码添加到您的通知服务中,以确保在Android 12及以上版本中正确设置通知渠道。
如果问题仍然存在,请检查您的应用程序是否有权接收通知,并确保在应用程序设置中启用了通知。