英文:
Are there restrictions with FirebaseMessagingService in Android 10+?
问题
我最近注意到在Android 10设备上出现了一些崩溃情况。
>java.lang.RuntimeException : 无法启动Activity ComponentInfo{com.acme.MainActivity}: java.lang.IllegalStateException: 不允许启动服务 Intent { cmp=com.acme/com.google.firebase.messaging.FirebaseMessagingService }: 应用在后台}
为了接收FCM消息,我使用了一个扩展FirebaseMessagingService的服务,并且我从MainActivity启动了这个服务:
Intent(this, MyFirebaseMessagingService::class.java).also {
intent -> startService(intent)
}
当然,我在清单文件中也有以下内容:
<service
android:name="com.acme.services.MyFirebaseMessagingService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
有了这一切,我正试图确定这个崩溃如何在Android 10启动时间歇性发生,或者如何激发它以显现出来。
英文:
I noticed some crashes recently on Android 10 devices
>java.lang.RuntimeException : Unable to start activity ComponentInfo{com.acme.MainActivity}: java.lang.IllegalStateException: Not allowed to start service Intent { cmp=com.acme/com.google.firebase.messaging.FirebaseMessagingService }: app is in background}
To receive FCM messages, I use a service that extends FirebaseMessagingService and I start the service from MainActvity using
Intent(this, MyFirebaseMessagingService::class.java).also {
intent -> startService(intent)
}
of course I have this in the manifest file
<service
android:name="com.acme.services.MyFirebaseMessagingService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
With that all in place I am trying to determine how this crash happens intermittently on startup for Android 10 and/or how can I motivate it to manifest itself.
答案1
得分: 0
FCM不需要启动,当你将FCM集成到你的应用程序中并在清单文件中注册它时,你可以接收FCM。
仔细阅读文档:
https://firebase.google.com/docs/cloud-messaging/android/client
英文:
FCM does't need to start, when you intergrate FCM into your app, register it in manifest, then you can receive FCM
Read the docs carefully:
https://firebase.google.com/docs/cloud-messaging/android/client
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论