Skip to content

Commit

Permalink
breaking(android): bump fcm@18.+ (havesource#19)
Browse files Browse the repository at this point in the history
* feat(android): bump fcm@18.+
* docs: include FMC_VERSION support notice
* docs: correct FCM_VERSION acceptable range

Co-authored-by: jcesarmobile <jcesarmobile@gmail.com>
  • Loading branch information
erisu and jcesarmobile committed Aug 29, 2020
1 parent 061c498 commit 1ae3428
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 15 deletions.
24 changes: 17 additions & 7 deletions docs/INSTALLATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,21 +137,31 @@ cordova plugin add --save cordova-plugin-facebook4 --variable APP_ID="App ID" --

### Co-existing with plugins that use Firebase

Problems may arise when push plugin is used along plugins that implement Firebase functionality (cordova-plugin-firebase-analytics, for example). Both plugins include a version of the FCM libraries.
Problems may arise when push plugin is used along plugins that implement Firebase functionality (e.g. `cordova-plugin-firebase-analytics`). Both plugins include a version of the FCM libraries.

To make the two work together, you need to migrate your GCM project from Google console to Firebase console:

1. In Firebase console - [import your existing GCM project](https://firebase.google.com/support/guides/google-android#migrate_your_console_project), don't create a new one.
2. Set your `FCM_VERSION` variable to match the version used in the other plugin. In case of cordova, your `config.xml` would look something like this:
1. In Firebase console - [import your existing GCM project](https://firebase.google.com/support/guides/google-android#migrate_your_console_project), don't create a new one.
2. Set your `FCM_VERSION` variable to match the version used in the other plugin. In case of Cordova, your `package.json` contains something like this:

```xml
<plugin name="phonegap-plugin-push" spec="~2.2.0">
<variable name="FCM_VERSION" value="15.0.0" />
</plugin>
```json
{
"cordova": {
"plugins": {
"cordova-plugin-push": {
"ANDROID_SUPPORT_V13_VERSION": "27.+",
"FCM_VERSION": "18.+"
}
},
"platforms": []
}
}
```

_Note:_ No changes on the back-end side are needed: [even though recommended](https://developers.google.com/cloud-messaging/android/android-migrate-fcm#update_server_endpoints), it isn't yet required and sending messages through GCM gateway should work just fine.

_Note:_ The `FCM_VERSION` must be greater than or equal to 17.1.0 and less than or equal to 18.0.0.

### Common errors

#### minSdkVersion === 14
Expand Down
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
</config-file>

<preference name="ANDROID_SUPPORT_V13_VERSION" default="28.0.0"/>
<preference name="FCM_VERSION" default="17.0.+"/>
<preference name="FCM_VERSION" default="18.+"/>

<framework src="com.android.support:support-v13:$ANDROID_SUPPORT_V13_VERSION"/>
<framework src="me.leolin:ShortcutBadger:1.1.17@aar"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,33 @@
import android.util.Log;

import com.google.firebase.iid.FirebaseInstanceId;
import com.google.firebase.iid.FirebaseInstanceIdService;
import com.google.firebase.iid.InstanceIdResult;
import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.android.gms.tasks.OnSuccessListener;

import org.json.JSONException;

import java.io.IOException;

public class PushInstanceIDListenerService extends FirebaseInstanceIdService implements PushConstants {
public static final String LOG_TAG = "Push_InsIdService";
public class PushInstanceIDListenerService extends FirebaseMessagingService implements PushConstants {
public static final String LOG_TAG = "Push_InsIdService";

@Override
public void onTokenRefresh() {
@Override
public void onNewToken(String s) {
super.onNewToken(s);

FirebaseInstanceId.getInstance().getInstanceId()
.addOnSuccessListener(new OnSuccessListener<InstanceIdResult>() {
@Override
public void onSuccess(InstanceIdResult instanceIdResult) {
// Get updated InstanceID token.
String refreshedToken = FirebaseInstanceId.getInstance().getToken();
String refreshedToken = instanceIdResult.getToken();

Log.d(LOG_TAG, "Refreshed token: " + refreshedToken);

// TODO: Implement this method to send any registration to your app's servers.
//sendRegistrationToServer(refreshedToken);
}
}
});
}
}

0 comments on commit 1ae3428

Please sign in to comment.