So now that the FirebaseInstanceIdService service is deprecated I'm unsure what to replace it with.
I previously had a service declared in the manifest like so:
<service
android:name=".fcm.FcmIdService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>
And the service itself:
public class FcmIdService extends FirebaseInstanceIdService {
@Override
public void onTokenRefresh() {
// Create notification channel.
createFcmNotificationChannel();
}
}
If I remove the service I no longer receive notifications so I'm assuming I have to replace it with something else.
Thanks.
EDIT: This question differs from the proposed duplicate question by also covering the manifest declaration of the affected services which is still unclear to me.
The token can be generated using the following code: FirebaseMessaging. getInstance(). getToken() .
Firebase Cloud Messaging Platform (formerly named as GCM) is a free mobile notification service by Google that enables (third-party) app developers to send notifications from GCM (Google Cloud Messaging) servers to their users.
Instance ID provides a unique identifier for each instance of your app and a mechanism to authenticate and authorize actions, like sending messages via Firebase Cloud Messaging. The InstanceID is long lived, but may expire for the following reasons: Device factory reset. User uninstalls the app.
Check this topic:
FirebaseInstanceIdService is deprecated
You have to replace it with:
public class MyFirebaseMessagingService extends FirebaseMessagingService {
@Override
public void onNewToken(String s) {
super.onNewToken(s);
Log.e("NEW_TOKEN",s);
}
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
}
}
And in manifest:
<service
android:name=".MyFirebaseMessagingService"
android:stopWithTask="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
And if you want to get token somewhere in your project:
FirebaseInstanceId.getInstance().getInstanceId().addOnSuccessListener( MyActivity.this, new OnSuccessListener<InstanceIdResult>() {
@Override
public void onSuccess(InstanceIdResult instanceIdResult) {
String newToken = instanceIdResult.getToken();
Log.e("newToken",newToken);
}
});
There is no need to use
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
Hope it helps you
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With