在我通过在AndroidManifest.xml中将键firebase_messaging_auto_init_enabled
设置为false
来禁用Firebase消息传递的自动初始化之后,使用自定义FirebaseMessagingService接收任何令牌或推送通知时遇到问题。
未将密钥设置为false
时,我的服务确实收到令牌。
我的意思是很明显,我确实需要初始化firebase消息才能检索令牌,但是我尝试的所有方法似乎都无效。
为了防止法律问题,我只想在我的Android应用程序的用户确实接受使用条款后启用Firebase /服务器通信。 这就是为什么我要防止自动初始化。用户确实接受了使用条款后,我想初始化该应用程序并将检索到的令牌发送到我的后端。
我已经尝试过的方法:
FirebaseApp.initializeApp(<Context>)
FirebaseMessaging.getInstance().setAutoInitEnabled(true)
实际上我可以使用方法FirebaseInstanceId.getInstance().getInstance()
来获得令牌,但我真的更喜欢使用FirebaseMessagingService,这似乎是一种更清洁的方法。
这是我的AndroidManifest中的一些代码:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application
android:usesCleartextTraffic="true">
<meta-data
android:name="firebase_messaging_auto_init_enabled"
android:value="false" />
<meta-data
android:name="firebase_analytics_collection_enabled"
android:value="false" />
<service
android:name="de.itkl.smartmobile.module.push.implementation.SMPushMessageService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
</application>
</manifest>