Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate instanceid service #959

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,12 @@ xmlns:android="http://schemas.android.com/apk/res/android">
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
<service android:name="org.apache.cordova.firebase.FirebasePluginInstanceIDService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>
<receiver android:name="org.apache.cordova.firebase.OnNotificationOpenReceiver"></receiver>
</config-file>
<resource-file src="src/android/google-services.json" target="."/>
<resource-file src="src/android/cordova-plugin-firebase-strings.xml" target="res/values/cordova-plugin-firebase-strings.xml" />
<source-file src="src/android/FirebasePlugin.java" target-dir="src/org/apache/cordova/firebase" />
<source-file src="src/android/OnNotificationOpenReceiver.java" target-dir="src/org/apache/cordova/firebase" />
<source-file src="src/android/FirebasePluginInstanceIDService.java" target-dir="src/org/apache/cordova/firebase" />
<source-file src="src/android/FirebasePluginMessagingService.java" target-dir="src/org/apache/cordova/firebase" />
<source-file src="src/android/FirebasePluginMessageReceiver.java" target-dir="src/org/apache/cordova/firebase" />
<source-file src="src/android/FirebasePluginMessageReceiverManager.java" target-dir="src/org/apache/cordova/firebase" />
Expand Down
13 changes: 13 additions & 0 deletions src/android/FirebasePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.google.firebase.FirebaseApp;
import com.google.firebase.analytics.FirebaseAnalytics;
import com.google.firebase.iid.FirebaseInstanceId;
import com.google.firebase.iid.InstanceIdResult;
import com.google.firebase.messaging.FirebaseMessaging;
import com.google.firebase.remoteconfig.FirebaseRemoteConfig;
import com.google.firebase.remoteconfig.FirebaseRemoteConfigInfo;
Expand Down Expand Up @@ -86,6 +87,18 @@ public void run() {
notificationStack.add(extras);
}
}

// Fetch initial FCM token
// This used to be done through FirebaseInstanceIdService, which has been deprecated.
// The replacement FirebaseMessagingService.onNewToken is not called for the first token.
FirebaseInstanceId.getInstance().getInstanceId().addOnSuccessListener(new OnSuccessListener<InstanceIdResult>() {
@Override
public void onSuccess(InstanceIdResult instanceIdResult) {
String token = instanceIdResult.getToken();
Log.d(TAG, "FCM Token initialized: " + token);
sendToken(token);
}
});
}
});
}
Expand Down
25 changes: 0 additions & 25 deletions src/android/FirebasePluginInstanceIDService.java

This file was deleted.

13 changes: 13 additions & 0 deletions src/android/FirebasePluginMessagingService.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,19 @@ private String getStringResource(String name) {
);
}

/**
* Called when a new token for the default Firebase project is generated.
*
* This is invoked after app install when a token is first generated, and again if the token changes.
*
* @param token The token used for sending messages to this application instance. This token is the same as the one retrieved by getInstanceId().
*/
@Override
public void onNewToken(String token) {
Log.d(TAG, "New FCM Token: " + token);
FirebasePlugin.sendToken(token);
}

/**
* Called when message is received.
*
Expand Down