{"_id":"588861fa165af631008ee1ca","parentDoc":null,"user":"548d74b716fc980b00e2a786","version":{"_id":"588861fa165af631008ee1b8","__v":1,"project":"54861bb654b3ce0b00367292","createdAt":"2017-01-25T08:29:46.061Z","releaseDate":"2017-01-25T08:29:46.061Z","categories":["588861fa165af631008ee1b9","588861fa165af631008ee1ba","588861fa165af631008ee1bb","588861fa165af631008ee1bc","588861fa165af631008ee1bd","588861fa165af631008ee1be","588861fa165af631008ee1bf","588861fa165af631008ee1c0","588861fa165af631008ee1c1","588861fa165af631008ee1c2","588861fa165af631008ee1c3","588861fa165af631008ee1c4","588861fa165af631008ee1c5","588861fa165af631008ee1c6","588861fa165af631008ee1c7","588861fa165af631008ee1c8","588861fa165af631008ee1c9"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"5.0.0","version":"5.0"},"category":{"_id":"588861fa165af631008ee1bc","__v":0,"version":"588861fa165af631008ee1b8","project":"54861bb654b3ce0b00367292","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2016-09-11T08:50:30.403Z","from_sync":false,"order":3,"slug":"android-essentials-kit","title":"Android / Essentials KIt"},"__v":0,"project":"54861bb654b3ce0b00367292","updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-09-11T08:51:04.250Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"settings":"","results":{"codes":[]},"auth":"never","params":[],"url":""},"isReference":false,"order":32,"body":"[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"Starting with this version the SDK is available as a gradle dependency\",\n  \"body\": \"If you got elasticode.aar file module in your project, remove it before you continue\"\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"1. Add the SDK\"\n}\n[/block]\n1.1. Add these lines to your **application**’s `build.gradle` file:\nBe sure to add this to your app module build.gradle and **not** under your project build.gradle\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"repositories {\\n    maven {\\n        url \\\"https://s3-eu-west-1.amazonaws.com/elasticode-sdk/Android/maven/\\\"\\n    }\\n}\\ndependencies {\\n    compile 'com.elasticode.sdk:elasticode-android:2.1.0'\\n}\",\n      \"language\": \"json\"\n    }\n  ]\n}\n[/block]\n1.2. Clean your project (Build -> Clean Project in Android Studio).\n\n1.3. Sync your project with gradle files (Sync Project with Gradle Files button in Android Studio).\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"2. Permissions to add into AndroidManifest.xml (Optional)\"\n}\n[/block]\nIf you want to take screenshots and your minSdkVersion is less than 19 you should declare WRITE_EXTERNAL_STORAGE permission in your AndroidManifest.xml:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<uses-permission\\n\\tandroid:name=\\\"android.permission.WRITE_EXTERNAL_STORAGE\\\"\\n  android:maxSdkVersion=\\\"18\\\" />\",\n      \"language\": \"xml\"\n    }\n  ]\n}\n[/block]\n**This permission is optional**, SDK can work without it.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"3. Start using Elasticode\"\n}\n[/block]\n3.1 Obtain instance of Elasticode singlethon with:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Elasticode elasticode = Elasticode.getInstance(this, API_KEY, elasticodeObserver);\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\nWhile `elasticodeObserver` allows you to be informed about elasticode notifications.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"private Observer elasticodeObserver = new Observer() {\\n\\t:::at:::Override\\n\\tpublic void update(Observable observable, Object data) {\\n\\t\\tif (data instanceof ElasticodeResponse) {\\n\\t\\t\\tElasticodeResponse response = (ElasticodeResponse) data;\\n\\t\\t\\tif (response.getError() != null) {\\n\\t\\t\\t\\t// In case of error\\n\\t\\t\\t} else {\\n\\t\\t\\t\\tswitch (response.getType()) {\\n\\t\\t\\t\\t\\tcase ON_LAUNCH_DISPLAYED:\\n            Boolean didApeared = ((Boolean) response.getAdditionalData());\\n\\t\\t\\t\\t\\t\\tbreak;\\n\\t\\t\\t\\t\\t// put here all types (ElasticodeResponseType) which you want to handle\\n\\t\\t\\t\\t}\\n        }\\n\\t\\t}\\n\\t}\\n};\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n3.2 When using [launchMode](https://developer.android.com/guide/topics/manifest/activity-element.html#lmode) is `singleInstance` or `singleTask`, Override the `onNewIntent` method to update the activity\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"@Override\\nprotected void onNewIntent(Intent intent) {\\n\\tsuper.onNewIntent(intent);\\n  elasticode.setNewIntent(intent);\\n}\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"4. Finally\"\n}\n[/block]\nWhen you’re done with all other possible configurations, you must call\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"elasticode.ready();\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"That's it!\"\n}\n[/block]\nYou are now good to run our <a href=\"http://helpdesk.elasticode.com/categories/1206-dynamic-onboarding\" target=\"_blank\">Dynamic onboarding</a> & <a href=\"http://helpdesk.elasticode.com/categories/1379-what-s-new\" target=\"_blank\">What's new</a>  services \n[block:callout]\n{\n  \"type\": \"success\",\n  \"title\": \"Actions & Analytics\",\n  \"body\": \"If you would like to provide more actions for buttons in your experiences or connect your experience to 3rd party analytics services, read about our [Extra setup](doc:extra-setup-actions-1)  (Optional)\"\n}\n[/block]","excerpt":"","slug":"setup-1","type":"basic","title":"Setup"}
[block:callout] { "type": "info", "title": "Starting with this version the SDK is available as a gradle dependency", "body": "If you got elasticode.aar file module in your project, remove it before you continue" } [/block] [block:api-header] { "type": "basic", "title": "1. Add the SDK" } [/block] 1.1. Add these lines to your **application**’s `build.gradle` file: Be sure to add this to your app module build.gradle and **not** under your project build.gradle [block:code] { "codes": [ { "code": "repositories {\n maven {\n url \"https://s3-eu-west-1.amazonaws.com/elasticode-sdk/Android/maven/\"\n }\n}\ndependencies {\n compile 'com.elasticode.sdk:elasticode-android:2.1.0'\n}", "language": "json" } ] } [/block] 1.2. Clean your project (Build -> Clean Project in Android Studio). 1.3. Sync your project with gradle files (Sync Project with Gradle Files button in Android Studio). [block:api-header] { "type": "basic", "title": "2. Permissions to add into AndroidManifest.xml (Optional)" } [/block] If you want to take screenshots and your minSdkVersion is less than 19 you should declare WRITE_EXTERNAL_STORAGE permission in your AndroidManifest.xml: [block:code] { "codes": [ { "code": "<uses-permission\n\tandroid:name=\"android.permission.WRITE_EXTERNAL_STORAGE\"\n android:maxSdkVersion=\"18\" />", "language": "xml" } ] } [/block] **This permission is optional**, SDK can work without it. [block:api-header] { "type": "basic", "title": "3. Start using Elasticode" } [/block] 3.1 Obtain instance of Elasticode singlethon with: [block:code] { "codes": [ { "code": "Elasticode elasticode = Elasticode.getInstance(this, API_KEY, elasticodeObserver);", "language": "java" } ] } [/block] While `elasticodeObserver` allows you to be informed about elasticode notifications. [block:code] { "codes": [ { "code": "private Observer elasticodeObserver = new Observer() {\n\t@Override\n\tpublic void update(Observable observable, Object data) {\n\t\tif (data instanceof ElasticodeResponse) {\n\t\t\tElasticodeResponse response = (ElasticodeResponse) data;\n\t\t\tif (response.getError() != null) {\n\t\t\t\t// In case of error\n\t\t\t} else {\n\t\t\t\tswitch (response.getType()) {\n\t\t\t\t\tcase ON_LAUNCH_DISPLAYED:\n Boolean didApeared = ((Boolean) response.getAdditionalData());\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t// put here all types (ElasticodeResponseType) which you want to handle\n\t\t\t\t}\n }\n\t\t}\n\t}\n};", "language": "java" } ] } [/block] 3.2 When using [launchMode](https://developer.android.com/guide/topics/manifest/activity-element.html#lmode) is `singleInstance` or `singleTask`, Override the `onNewIntent` method to update the activity [block:code] { "codes": [ { "code": "@Override\nprotected void onNewIntent(Intent intent) {\n\tsuper.onNewIntent(intent);\n elasticode.setNewIntent(intent);\n}", "language": "java" } ] } [/block] [block:api-header] { "type": "basic", "title": "4. Finally" } [/block] When you’re done with all other possible configurations, you must call [block:code] { "codes": [ { "code": "elasticode.ready();", "language": "java" } ] } [/block] [block:api-header] { "type": "basic", "title": "That's it!" } [/block] You are now good to run our <a href="http://helpdesk.elasticode.com/categories/1206-dynamic-onboarding" target="_blank">Dynamic onboarding</a> & <a href="http://helpdesk.elasticode.com/categories/1379-what-s-new" target="_blank">What's new</a> services [block:callout] { "type": "success", "title": "Actions & Analytics", "body": "If you would like to provide more actions for buttons in your experiences or connect your experience to 3rd party analytics services, read about our [Extra setup](doc:extra-setup-actions-1) (Optional)" } [/block]