user1519979 user1519979 - 26 days ago 6
Android Question

Disabling FirebaseMessagingService programmatically

I'm using Firebase for receiving Pushnotifications. My problem is that i want to make an option for users available, where they can disable these Notifications.

<application android:label="MyApp" android:theme="@android:style/Theme.NoTitleBar" android:icon="@drawable/ico_myapp_application">
<receiver android:name="com.google.firebase.iid.FirebaseInstanceIdInternalReceiver" android:exported="false" />
<receiver android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver" android:exported="true" android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="${applicationId}" />
</intent-filter>
</receiver>
<!-- END Manual Firebase Additions -->
</application>


Is there a way to prevent the app from register/creating the FirebaseMessagingService ?

Answer

You could make options for users to Unsubscribe from your Firebase topic, they would stop getting the notifications. Unless if you are sending it directly to their ID.

FirebaseMessaging.getInstance().subscribeToTopic("news");

and then unsubscribe users

FirebaseMessaging.getInstance().unsubscribeFromTopic("news");