{"_id":"5b720760c44b7600034b7a07","project":"55e67aaa9cc7c62b00c4a1ea","version":{"_id":"5b720760c44b7600034b7a08","project":"55e67aaa9cc7c62b00c4a1ea","__v":0,"forked_from":"5b1f2cbdfd653400031d8d9f","createdAt":"2015-09-02T04:27:23.612Z","releaseDate":"2015-09-02T04:27:23.612Z","categories":["5b720760c44b7600034b79a7","5b720760c44b7600034b79a8","5b720760c44b7600034b79a9","5b720760c44b7600034b79aa","5b720760c44b7600034b79ab","561c61b4ad272c0d00a892df","586c014c0abf1d0f000d04d4","58991d2ad207df0f0002186b","5b720760c44b7600034b79ac","5b720760c44b7600034b79ad","5af0fe494ca2730003cbc98a","5af0fe55ec80af0003804ca2"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"API V6","version_clean":"1.4.0","version":"1.4"},"category":{"_id":"5b720760c44b7600034b79a8","__v":35,"pages":["5b720760c44b7600034b79b1","5b720760c44b7600034b79b3","5b720760c44b7600034b79b4","5b720760c44b7600034b79b5","55e682b7de6fef23009480dc","5b720760c44b7600034b79b6","5b720760c44b7600034b79b7","5b720760c44b7600034b79b8","5b720760c44b7600034b79b9","5b720760c44b7600034b79ba","5b720760c44b7600034b79bb","5b720760c44b7600034b79bc","5b720760c44b7600034b79bd","5b720760c44b7600034b79d1","5b720760c44b7600034b79d2","5b720760c44b7600034b79d3","5b720760c44b7600034b79d4","5b720760c44b7600034b79d5","5b720760c44b7600034b79d8","5b720760c44b7600034b79d9","5b720760c44b7600034b79db","561c6ca0be5fb20d00077754","5b720760c44b7600034b79e0","5b720760c44b7600034b79e1","5b720760c44b7600034b79e2","5b720760c44b7600034b79e3","5b720760c44b7600034b79e4","5b720760c44b7600034b79e5","5b720760c44b7600034b79e6","56cfa5386c5d7a13005eec0f","56e73d86555c030e00a52a73","56e7460c9000b120000ffe2e","56e8c19e99c6400e003820cf","56e8c53fc88bf80e00f8bed8","56f06ff4d386ce0e008e9b21"],"project":"55e67aaa9cc7c62b00c4a1ea","version":"5b720760c44b7600034b7a08","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-09-02T04:30:13.305Z","from_sync":false,"order":1,"slug":"install-in-your-app","title":"Install in your app"},"user":"5b0b7a46a26e6400036604fd","githubsync":"","__v":0,"parentDoc":null,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2018-07-31T04:26:15.660Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":30,"body":"If you are updating from an older version of the Android SDK to version 6+, there are certain things you will need to check to ensure that your app will still receive push notifications.\n\n1. The app has a project set up in the Firebase Console.\n2. The app has a google-services.json file downloaded from the Firebase Console project.\n3. The debug and release SHA-1 values for the app have been added to the Firebase Console project.\n4. The app has the Google Services plugin applied in the build.gradle file.\n5. The Android Manifest has been updated.\n6. Gradle dependencies are up to date.\n7. FirebaseMessagingService implementation.\n\n\n### Firebase Console\n\nIn order to use Firebase in your app, it needs to have a project set up in the Firebase Console. If you are still working from the Google Cloud Console, please see our [guide to migrating to Firebase](http://docs.carnival.io/docs/migrating-to-firebase-cloud-messaging).\n\n\n### Google Services JSON\n\nYou can download a google-services.json file for your app from the Firebase Console. This needs to be added to the root directory of your app. The Firebase SDK then uses it to access details about your app and its respective Firebase Console project. If you don't already have it, you can download it from the project settings:\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/7fa7f61-Screen_Shot_2018-07-31_at_12.37.29_PM.png\",\n        \"Screen Shot 2018-07-31 at 12.37.29 PM.png\",\n        469,\n        160,\n        \"#f1f0ee\"\n      ]\n    }\n  ]\n}\n[/block]\nIn the General tab you should be able to find your app in the 'Your apps' section. You should then be able to download the JSON file from the 'Download the latest config file' section:\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/14829ee-Screen_Shot_2018-08-01_at_11.16.02_AM.png\",\n        \"Screen Shot 2018-08-01 at 11.16.02 AM.png\",\n        639,\n        128,\n        \"#cfd2d3\"\n      ]\n    }\n  ]\n}\n[/block]\nMore information about adding the the google-services.json file to your app can be found in Google's developer documentation [here](https://developers.google.com/android/guides/google-services-plugin#adding_the_json_file \"https://developers.google.com/android/guides/google-services-plugin#adding_the_json_file\").\n\n\n### Google Services\n\nThe Firebase SDK requires Google Services in the app. To provide this the Google Services dependency needs to be added to your project level build.gradle file:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"buildscript {\\n    dependencies {\\n        classpath 'com.google.gms:google-services:4.0.1'\\n    }\\n}\",\n      \"language\": \"groovy\"\n    }\n  ]\n}\n[/block]\nThe Google Services plugin also needs to be applied in your app's build.gradle file. This should be added to the **bottom** of the app-level build.gradle file:\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"apply plugin: 'com.google.gms.google-services'\",\n      \"language\": \"groovy\"\n    }\n  ]\n}\n[/block]\n### Remove Unnecessary Values from AndroidManifest\n\nThe Firebase SDK handles permissions itself, so you can (and should) remove these values from your app's AndroidManifest.xml. leaving some of these values in the manifest can lead to crashes.\n[block:callout]\n{\n  \"type\": \"warning\",\n  \"title\": \"\",\n  \"body\": \"Leaving some of these values in the manifest can lead to crashes. Make sure you remove them all!\"\n}\n[/block]\nBetween the `<manifest> </manifest>` tags, delete the following values:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<uses-permission android:name=\\\"android.permission.WAKE_LOCK\\\" />\\n<uses-permission android:name=\\\"com.google.android.c2dm.permission.RECEIVE\\\" />\\n\\n<uses-permission android:name=\\\"${applicationId}.permission.C2D_MESSAGE\\\" />\\n\\n<permission\\n  android:name=\\\"${applicationId}.permission.C2D_MESSAGE\\\"\\n  android:protectionLevel=\\\"signature\\\" />\",\n      \"language\": \"xml\"\n    }\n  ]\n}\n[/block]\nBetween the `<application> </application>` tags, delete these values:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<receiver\\n  android:name=\\\"com.google.android.gms.gcm.GcmReceiver\\\"\\n  android:exported=\\\"true\\\"\\n  android:permission=\\\"com.google.android.c2dm.permission.SEND\\\" >\\n  <intent-filter>\\n      <action android:name=\\\"com.google.android.c2dm.intent.RECEIVE\\\" />\\n      <category android:name=\\\"${applicationId}\\\" />\\n  </intent-filter>\\n</receiver>\\n\\n<meta-data\\n  android:name=\\\"com.google.android.gms.version\\\"\\n  android:value=\\\":::at:::integer/google_play_services_version\\\" />\",\n      \"language\": \"xml\"\n    }\n  ]\n}\n[/block]\n### Gradle Dependencies\n\nThe Android SDK is now utilising the Firebase messaging library. Since the version is greater than version 15.0.0, there is a requirement that all play services and firebase libraries included in your app also be at least version 15.0.0. This requirement was put in place by Google when they moved to semantic versioning from release 15.0.0 onwards. Further details can be found [here](https://android-developers.googleblog.com/2018/05/announcing-new-sdk-versioning.html?m=1 \"https://android-developers.googleblog.com/2018/05/announcing-new-sdk-versioning.html?m=1\").\n\nThe Firebase messaging library and play services GCM library cannot be present in the same application, so you should ensure the play services GCM library is removed from the build.gradle file.\n\nIf you do not include the Firebase Core library in your app dependencies you may receive a Java Compiler warning: \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Warning: The app gradle file must have a dependency on com.google.firebase:firebase-core for Firebase services to work as intended.\",\n      \"language\": \"text\"\n    }\n  ]\n}\n[/block]\nFirebase messaging notifications will still be received without adding the core library, so it is not required for the Sailthru Mobile SDK to work correctly, however some of the additional functionality Firebase offers in the console may not work without it.\n\n### FirebaseMessagingService Implementation\n\nFirebase sends tokens and notifications to the app through an implementation of the FirebaseMessagingService class. The SDK implements this class internally so your app can work with Firebase without having to create its own implementation. If, however, your app does have an implementation of the FirebaseMessagingService class then it will override the one that is implemented in the SDK. In this case in order for the SDK to function correctly you must pass the token and any received notifications to the SDK manually through the Carnival.setDeviceToken() and Carnival.handleNotification() methods:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"import com.carnival.sdk.Carnival;\\nimport com.google.firebase.messaging.FirebaseMessagingService;\\nimport com.google.firebase.messaging.RemoteMessage;\\n\\n/**\\n * Your app's implementation of FirebaseMessagingService.\\n */\\npublic final class AppFirebaseService extends FirebaseMessagingService {\\n\\n    @Override\\n    public void onMessageReceived(RemoteMessage remoteMessage) {\\n      \\n      \\t// Your code for handling notification\\n      \\n      \\t// Pass notification through to Carnival\\n        Carnival.handleNotification(remoteMessage);\\n    }\\n\\n    @Override\\n    public void onNewToken(String token) {\\n      \\t\\n      \\t// Your code for handling token\\n      \\n      \\t// Pass token through to Carnival\\n        Carnival.setDeviceToken(token);\\n    }\\n}\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]","excerpt":"","slug":"android-updating-to-version-6","type":"basic","title":"Android: Updating to Version 6"}

Android: Updating to Version 6


If you are updating from an older version of the Android SDK to version 6+, there are certain things you will need to check to ensure that your app will still receive push notifications. 1. The app has a project set up in the Firebase Console. 2. The app has a google-services.json file downloaded from the Firebase Console project. 3. The debug and release SHA-1 values for the app have been added to the Firebase Console project. 4. The app has the Google Services plugin applied in the build.gradle file. 5. The Android Manifest has been updated. 6. Gradle dependencies are up to date. 7. FirebaseMessagingService implementation. ### Firebase Console In order to use Firebase in your app, it needs to have a project set up in the Firebase Console. If you are still working from the Google Cloud Console, please see our [guide to migrating to Firebase](http://docs.carnival.io/docs/migrating-to-firebase-cloud-messaging). ### Google Services JSON You can download a google-services.json file for your app from the Firebase Console. This needs to be added to the root directory of your app. The Firebase SDK then uses it to access details about your app and its respective Firebase Console project. If you don't already have it, you can download it from the project settings: [block:image] { "images": [ { "image": [ "https://files.readme.io/7fa7f61-Screen_Shot_2018-07-31_at_12.37.29_PM.png", "Screen Shot 2018-07-31 at 12.37.29 PM.png", 469, 160, "#f1f0ee" ] } ] } [/block] In the General tab you should be able to find your app in the 'Your apps' section. You should then be able to download the JSON file from the 'Download the latest config file' section: [block:image] { "images": [ { "image": [ "https://files.readme.io/14829ee-Screen_Shot_2018-08-01_at_11.16.02_AM.png", "Screen Shot 2018-08-01 at 11.16.02 AM.png", 639, 128, "#cfd2d3" ] } ] } [/block] More information about adding the the google-services.json file to your app can be found in Google's developer documentation [here](https://developers.google.com/android/guides/google-services-plugin#adding_the_json_file "https://developers.google.com/android/guides/google-services-plugin#adding_the_json_file"). ### Google Services The Firebase SDK requires Google Services in the app. To provide this the Google Services dependency needs to be added to your project level build.gradle file: [block:code] { "codes": [ { "code": "buildscript {\n dependencies {\n classpath 'com.google.gms:google-services:4.0.1'\n }\n}", "language": "groovy" } ] } [/block] The Google Services plugin also needs to be applied in your app's build.gradle file. This should be added to the **bottom** of the app-level build.gradle file: [block:code] { "codes": [ { "code": "apply plugin: 'com.google.gms.google-services'", "language": "groovy" } ] } [/block] ### Remove Unnecessary Values from AndroidManifest The Firebase SDK handles permissions itself, so you can (and should) remove these values from your app's AndroidManifest.xml. leaving some of these values in the manifest can lead to crashes. [block:callout] { "type": "warning", "title": "", "body": "Leaving some of these values in the manifest can lead to crashes. Make sure you remove them all!" } [/block] Between the `<manifest> </manifest>` tags, delete the following values: [block:code] { "codes": [ { "code": "<uses-permission android:name=\"android.permission.WAKE_LOCK\" />\n<uses-permission android:name=\"com.google.android.c2dm.permission.RECEIVE\" />\n\n<uses-permission android:name=\"${applicationId}.permission.C2D_MESSAGE\" />\n\n<permission\n android:name=\"${applicationId}.permission.C2D_MESSAGE\"\n android:protectionLevel=\"signature\" />", "language": "xml" } ] } [/block] Between the `<application> </application>` tags, delete these values: [block:code] { "codes": [ { "code": "<receiver\n android:name=\"com.google.android.gms.gcm.GcmReceiver\"\n android:exported=\"true\"\n android:permission=\"com.google.android.c2dm.permission.SEND\" >\n <intent-filter>\n <action android:name=\"com.google.android.c2dm.intent.RECEIVE\" />\n <category android:name=\"${applicationId}\" />\n </intent-filter>\n</receiver>\n\n<meta-data\n android:name=\"com.google.android.gms.version\"\n android:value=\"@integer/google_play_services_version\" />", "language": "xml" } ] } [/block] ### Gradle Dependencies The Android SDK is now utilising the Firebase messaging library. Since the version is greater than version 15.0.0, there is a requirement that all play services and firebase libraries included in your app also be at least version 15.0.0. This requirement was put in place by Google when they moved to semantic versioning from release 15.0.0 onwards. Further details can be found [here](https://android-developers.googleblog.com/2018/05/announcing-new-sdk-versioning.html?m=1 "https://android-developers.googleblog.com/2018/05/announcing-new-sdk-versioning.html?m=1"). The Firebase messaging library and play services GCM library cannot be present in the same application, so you should ensure the play services GCM library is removed from the build.gradle file. If you do not include the Firebase Core library in your app dependencies you may receive a Java Compiler warning: [block:code] { "codes": [ { "code": "Warning: The app gradle file must have a dependency on com.google.firebase:firebase-core for Firebase services to work as intended.", "language": "text" } ] } [/block] Firebase messaging notifications will still be received without adding the core library, so it is not required for the Sailthru Mobile SDK to work correctly, however some of the additional functionality Firebase offers in the console may not work without it. ### FirebaseMessagingService Implementation Firebase sends tokens and notifications to the app through an implementation of the FirebaseMessagingService class. The SDK implements this class internally so your app can work with Firebase without having to create its own implementation. If, however, your app does have an implementation of the FirebaseMessagingService class then it will override the one that is implemented in the SDK. In this case in order for the SDK to function correctly you must pass the token and any received notifications to the SDK manually through the Carnival.setDeviceToken() and Carnival.handleNotification() methods: [block:code] { "codes": [ { "code": "import com.carnival.sdk.Carnival;\nimport com.google.firebase.messaging.FirebaseMessagingService;\nimport com.google.firebase.messaging.RemoteMessage;\n\n/**\n * Your app's implementation of FirebaseMessagingService.\n */\npublic final class AppFirebaseService extends FirebaseMessagingService {\n\n @Override\n public void onMessageReceived(RemoteMessage remoteMessage) {\n \n \t// Your code for handling notification\n \n \t// Pass notification through to Carnival\n Carnival.handleNotification(remoteMessage);\n }\n\n @Override\n public void onNewToken(String token) {\n \t\n \t// Your code for handling token\n \n \t// Pass token through to Carnival\n Carnival.setDeviceToken(token);\n }\n}", "language": "java" } ] } [/block]