{"_id":"588861fa165af631008ee1cd","parentDoc":null,"user":"548d74b716fc980b00e2a786","project":"54861bb654b3ce0b00367292","__v":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"},"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"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-09-11T09:24:43.584Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":35,"body":"[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"public class MainActivity extends AppCompatActivity {\\n    private final static String TAG = MainActivity.class.getSimpleName();\\n \\t\\t// elasticode instance\\n    private Elasticode elasticode;\\n    :::at:::Override\\n    protected void onCreate(Bundle savedInstanceState) {\\n        super.onCreate(savedInstanceState);\\n        setContentView(R.layout.activity_main);\\n\\n      \\t// set your key\\n        elasticode = Elasticode.getInstance(this, \\\"<APIKey>\\\", elasticodeObserver);\\n      \\n      \\t// add action\\n        ElasticodeAction showVideoAction = \\n          new ElasticodeAction(\\\"Show video\\\", new ElasticodeOnClickListener() {\\n            @Override\\n            public void onClick(View v) {\\n                super.onClick(v);\\n                // Show video\\n            }\\n        });\\n        elasticode.addActions(showVideoAction);\\n      \\n      \\t// set 3rd party analytics\\n        elasticode.setThirdPartyAnalytics(\\\"Mixpanel\\\", new ElasticodeBlock() {\\n            @Override\\n            public void perform(String eventName) {\\n                mixpanel.track(eventName, new JSONObject());\\n            }\\n        });\\n\\n        elasticode.ready();\\n    }\\n  \\n\\t  @Override\\n    protected void onNewIntent(Intent intent) {\\n        super.onNewIntent(intent);\\n        elasticode.setNewIntent(intent);\\n    }\\n  \\n    private Observer elasticodeObserver = new Observer() {\\n        @Override\\n        public void update(Observable observable, Object data) {\\n            if (data instanceof ElasticodeResponse) {\\n                ElasticodeResponse response = (ElasticodeResponse) data;\\n                if (response.getError() != null) {\\n                    Log.d(TAG, \\\"Error: \\\" + response.getError());\\n                }else{\\n                \\tswitch (response.getType()) {\\n                      case SESSION_STARTED:\\n                      // Elasticode in sync\\n                        Toast.makeText(MainActivity.this, \\\"Sync done\\\", Toast.LENGTH_LONG).show();\\n                        break;\\n                      case ON_LAUNCH_DISPLAYED:\\n                        Log.d(TAG, \\\"ON_LAUNCH_DISPLAYED: \\\" + ((Boolean) response.getAdditionalData()));\\n                        Toast.makeText(MainActivity.this, \\\"ON_LAUNCH_DISPLAYED: \\\" + ((Boolean) response.getAdditionalData()),\\n                                Toast.LENGTH_LONG).show();\\n                        break;\\n                \\t}\\n                }\\n            }\\n        }\\n    };\\n}\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]","excerpt":"","slug":"integration-example","type":"basic","title":"Integration example"}

Integration example


[block:code] { "codes": [ { "code": "public class MainActivity extends AppCompatActivity {\n private final static String TAG = MainActivity.class.getSimpleName();\n \t\t// elasticode instance\n private Elasticode elasticode;\n @Override\n protected void onCreate(Bundle savedInstanceState) {\n super.onCreate(savedInstanceState);\n setContentView(R.layout.activity_main);\n\n \t// set your key\n elasticode = Elasticode.getInstance(this, \"<APIKey>\", elasticodeObserver);\n \n \t// add action\n ElasticodeAction showVideoAction = \n new ElasticodeAction(\"Show video\", new ElasticodeOnClickListener() {\n @Override\n public void onClick(View v) {\n super.onClick(v);\n // Show video\n }\n });\n elasticode.addActions(showVideoAction);\n \n \t// set 3rd party analytics\n elasticode.setThirdPartyAnalytics(\"Mixpanel\", new ElasticodeBlock() {\n @Override\n public void perform(String eventName) {\n mixpanel.track(eventName, new JSONObject());\n }\n });\n\n elasticode.ready();\n }\n \n\t @Override\n protected void onNewIntent(Intent intent) {\n super.onNewIntent(intent);\n elasticode.setNewIntent(intent);\n }\n \n private Observer elasticodeObserver = new Observer() {\n @Override\n public void update(Observable observable, Object data) {\n if (data instanceof ElasticodeResponse) {\n ElasticodeResponse response = (ElasticodeResponse) data;\n if (response.getError() != null) {\n Log.d(TAG, \"Error: \" + response.getError());\n }else{\n \tswitch (response.getType()) {\n case SESSION_STARTED:\n // Elasticode in sync\n Toast.makeText(MainActivity.this, \"Sync done\", Toast.LENGTH_LONG).show();\n break;\n case ON_LAUNCH_DISPLAYED:\n Log.d(TAG, \"ON_LAUNCH_DISPLAYED: \" + ((Boolean) response.getAdditionalData()));\n Toast.makeText(MainActivity.this, \"ON_LAUNCH_DISPLAYED: \" + ((Boolean) response.getAdditionalData()),\n Toast.LENGTH_LONG).show();\n break;\n \t}\n }\n }\n }\n };\n}", "language": "java" } ] } [/block]