FirebaseMessagingService 在 Android 10+ 中有限制吗?

huangapple go评论66阅读模式
英文:

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

huangapple
  • 本文由 发表于 2023年3月3日 22:34:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/75628380.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定