Firebase 推送在其他进程中初始化后未收到

问题描述 投票:0回答:1

在优化方面,我决定在其他进程中初始化推送,它在android 10及更高版本中运行良好,但推送在较低版本的android中不显示

我需要它在所有 Android 版本中都能正常工作

这是我的清单代码

<receiver
            android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver"
            android:exported="true"
            android:permission="com.google.android.c2dm.permission.SEND"
            android:process=":pushprocess"
            tools:node="replace">
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            </intent-filter>
        </receiver>

        <service
            android:name="FirebaseMessagingService"
            android:exported="false"
            tools:node="replace"
            android:process=":pushprocess">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>
        </service>
android firebase push-notification firebase-cloud-messaging
1个回答
0
投票

我认为“其他进程”是指协程。 firebase 通知是否在应用程序上执行某些操作?它是否显示应用内消息?

如果是这样,那么您需要确保接收 firebase 通知的协程编组主线程上的表示逻辑。

所以在你的情况下这样做(一个展示原理的例子):

fun receiveFirebaseMessage(data: String){

   withContext(Dispatchers.Main) {
        //present an in-app message or any UI logic for the app here
   } 
}
© www.soinside.com 2019 - 2024. All rights reserved.