'Can firebase messaging services can be android:exported="false"?
Like to confirm if we can set android:exported="false"
for instance id service and messaging service.
I tested by keeping android:exported="false"
and notifications are working fine.
<service
android:name=".MyFirebaseMessagingService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
<service
android:name=".MyFirebaseInstanceIDService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>
Solution 1:[1]
The firebase-messaging library exports an unspecialized FirebaseMessagingService
of its own with low priority (-500). You can see it in your merged AndroidManifest.xml. This service can handle the push messages that carry notifications, like the ones you can send through the Firebase console.
If your specialized service class isn't exported, then the system will route messages from the Google services package to this unspecialized service, and notifications will work fine.
But that means you wouldn't be able to, for example, perform other actions when receiving a message or process custom data payloads.
Solution 2:[2]
You should export the service to be sure it is handled by your class as specified by @guest
<service
android:name=".services.MyFirebaseMessagingService"
android:exported="true">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | guest |
Solution 2 |