一旦我看到这个错误,我搜索了足够的谷歌,意识到这是一个明显的元数据问题,所以我在修复它并做了大量工作后提出了这个问题。
例如,清单default_notification_channel -> default_notification_channel_id
我的原木猫
2021-08-15 14:03:05.326 26315-27157/com.project W/FirebaseMessaging: Notification Channel requested (fcm_default_channel) has not been created by the app. Manifest configuration, or default, value will be used.
2021-08-15 14:03:05.327 26315-27157/com.project W/FirebaseMessaging: Notification Channel set in AndroidManifest.xml has not been created by the app. Default value will be used.
我的清单
<service
android:name=".ui.fcm.MyFirebaseMessagingService"
android:stopWithTask="false"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>
<meta-data
android:name="com.google.firebase.messaging.default_notification_channel_id"
android:value="@string/default_notification_channel_id"/>
和我的fcm服务类
class MyFirebaseMessagingService : FirebaseMessagingService() {
override fun onNewToken(token: String) {
Timber.d("Refreshed token: $token")
//TODO : Token save
}
override fun onMessageReceived(remoteMessage: RemoteMessage) {
Timber.d("MyFirebaseMessagingService onMessageReceived 성공!!!!")
if (remoteMessage.notification != null) {
Timber.d("MyFirebaseMessagingService noti.body = ${remoteMessage.notification?.body}")
sendNotification(remoteMessage)
}
if (remoteMessage.data.isEmpty()) {
return
}
super.onMessageReceived(remoteMessage)
}
private fun sendNotification(remoteMessage: RemoteMessage) {
val uniId: Int = (System.currentTimeMillis() / 7).toInt()
val intent = Intent(this, MainActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
val pendingIntent =
PendingIntent.getActivity(this, uniId, intent, PendingIntent.FLAG_ONE_SHOT)
val channelId = getString(R.string.default_notification_channel_id)
val soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
val notificationBuilder = NotificationCompat.Builder(this, channelId)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(remoteMessage.data["body"].toString())
.setContentText(remoteMessage.data["title"].toString())
.setAutoCancel(true)
.setSound(soundUri)
.setContentIntent(pendingIntent)
val notificationManager =
getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val channel =
NotificationChannel(channelId, "Notice", NotificationManager.IMPORTANCE_DEFAULT)
notificationManager.createNotificationChannel(channel)
}
notificationManager.notify(uniId, notificationBuilder.build())
}
}
我之所以问这个问题,是因为在我将数据保存到房间时,fcm不能正常工作。推送消息来了,但是数据没有记录下来,我不确定是否有正确的数据来了,因为这样的错误正在出来。
我还没能解决这个问题,你还能帮我吗?
发布于 2021-08-15 07:09:29
在服务标签中再添加一个意图过滤器。喜欢,
<service
android:name=".firebase.MessagingService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
添加这个完全相同的意图过滤器标记。
https://stackoverflow.com/questions/68788894
复制相似问题