由于 Android 13 SDK 中的通知权限最近发生了变化,我需要使用 FCM 集成更新我的应用程序以遵守通知规则。我已将compileSdk升级到33,并将targetSdk升级到33。我编写了代码来询问POST_NOTIFICATIONS,然后出现提示。按“允许”后,将启用通知权限。但在发送推送通知时,应用程序不会收到任何通知。
我只是在请求通知许可时进行了更改。没有更改 FirebaseMessagingService 类中的任何内容。该应用程序以前是 targetSdk 30。
class MyFirebaseMessagingService : FirebaseMessagingService() {
var intent: Intent? = null
var badgecount: Int = 0
override fun onMessageReceived(remoteMessage: RemoteMessage) {
if (remoteMessage.data.isNotEmpty()) {
try {
val json = JSONObject(remoteMessage.data.toString())
handleDataMessage(json)
} catch (e: Exception) {
Log.e("FIREBASEEXCEPTION:", e.message.toString())
}
}
if (remoteMessage.notification != null) {
sendNotification(remoteMessage.notification!!.body)
println("Message Notification Body:" + remoteMessage.notification!!.body)
}
super.onMessageReceived(remoteMessage)
}
private fun handleDataMessage(json: JSONObject) {
try {
val data = json.getJSONObject("body")
val badge = data.getString("badge") …Run Code Online (Sandbox Code Playgroud) android push-notification kotlin firebase-cloud-messaging android-13