File tree Expand file tree Collapse file tree 4 files changed +26
-31
lines changed Expand file tree Collapse file tree 4 files changed +26
-31
lines changed Original file line number Diff line number Diff line change @@ -37,18 +37,12 @@ xmlns:android="http://schemas.android.com/apk/res/android">
3737 <action android : name =" com.google.firebase.MESSAGING_EVENT" />
3838 </intent-filter >
3939 </service >
40- <service android : name =" org.apache.cordova.firebase.FirebasePluginInstanceIDService" >
41- <intent-filter >
42- <action android : name =" com.google.firebase.INSTANCE_ID_EVENT" />
43- </intent-filter >
44- </service >
4540 <receiver android : name =" org.apache.cordova.firebase.OnNotificationOpenReceiver" ></receiver >
4641 </config-file >
4742 <resource-file src =" src/android/google-services.json" target =" ." />
4843 <resource-file src =" src/android/cordova-plugin-firebase-strings.xml" target =" res/values/cordova-plugin-firebase-strings.xml" />
4944 <source-file src =" src/android/FirebasePlugin.java" target-dir =" src/org/apache/cordova/firebase" />
5045 <source-file src =" src/android/OnNotificationOpenReceiver.java" target-dir =" src/org/apache/cordova/firebase" />
51- <source-file src =" src/android/FirebasePluginInstanceIDService.java" target-dir =" src/org/apache/cordova/firebase" />
5246 <source-file src =" src/android/FirebasePluginMessagingService.java" target-dir =" src/org/apache/cordova/firebase" />
5347 <source-file src =" src/android/FirebasePluginMessageReceiver.java" target-dir =" src/org/apache/cordova/firebase" />
5448 <source-file src =" src/android/FirebasePluginMessageReceiverManager.java" target-dir =" src/org/apache/cordova/firebase" />
Original file line number Diff line number Diff line change 1919import com .google .firebase .FirebaseApp ;
2020import com .google .firebase .analytics .FirebaseAnalytics ;
2121import com .google .firebase .iid .FirebaseInstanceId ;
22+ import com .google .firebase .iid .InstanceIdResult ;
2223import com .google .firebase .messaging .FirebaseMessaging ;
2324import com .google .firebase .remoteconfig .FirebaseRemoteConfig ;
2425import com .google .firebase .remoteconfig .FirebaseRemoteConfigInfo ;
@@ -86,6 +87,18 @@ public void run() {
8687 notificationStack .add (extras );
8788 }
8889 }
90+
91+ // Fetch initial FCM token
92+ // This used to be done through FirebaseInstanceIdService, which has been deprecated.
93+ // The replacement FirebaseMessagingService.onNewToken is not called for the first token.
94+ FirebaseInstanceId .getInstance ().getInstanceId ().addOnSuccessListener (new OnSuccessListener <InstanceIdResult >() {
95+ @ Override
96+ public void onSuccess (InstanceIdResult instanceIdResult ) {
97+ String token = instanceIdResult .getToken ();
98+ Log .d (TAG , "FCM Token initialized: " + token );
99+ sendToken (token );
100+ }
101+ });
89102 }
90103 });
91104 }
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -40,6 +40,19 @@ private String getStringResource(String name) {
4040 );
4141 }
4242
43+ /**
44+ * Called when a new token for the default Firebase project is generated.
45+ *
46+ * This is invoked after app install when a token is first generated, and again if the token changes.
47+ *
48+ * @param token The token used for sending messages to this application instance. This token is the same as the one retrieved by getInstanceId().
49+ */
50+ @ Override
51+ public void onNewToken (String token ) {
52+ Log .d (TAG , "New FCM Token: " + token );
53+ FirebasePlugin .sendToken (token );
54+ }
55+
4356 /**
4457 * Called when message is received.
4558 *
You can’t perform that action at this time.
0 commit comments