{"_id":"576d42354bcd290e00428952","__v":9,"version":{"_id":"576d42354bcd290e00428941","project":"56a526d4e7a1622b0024fae4","__v":1,"createdAt":"2016-06-24T14:22:45.076Z","releaseDate":"2016-06-24T14:22:45.076Z","categories":["576d42354bcd290e00428942","576d42354bcd290e00428943","576d42354bcd290e00428944","576d42354bcd290e00428945","576d42354bcd290e00428946","576d42354bcd290e00428947"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"2.0.0","version":"2"},"category":{"_id":"576d42354bcd290e00428943","__v":0,"project":"56a526d4e7a1622b0024fae4","version":"576d42354bcd290e00428941","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2016-02-11T15:53:26.341Z","from_sync":false,"order":1,"slug":"platforms","title":"Our SDKs"},"parentDoc":null,"project":"56a526d4e7a1622b0024fae4","user":"56c1c2bb6811970d0032bb1f","updates":["58a46ce45c23851b000cffe8","58f629ca58048b19006063d1","591f1302680cb12300647a28"],"next":{"pages":[],"description":""},"createdAt":"2016-06-23T17:33:19.875Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":3,"body":"The Chirp Android SDK is designed to get your Android devices Chirping quickly and easily. \n\nThis guide will lead you through the steps required to get your App Chirping. We will show you how to:\n\n* Install the Chirp SDK\n* Setup the Chirp SDK\n* Start Chirping\n\nWe will be calling several of the Chirp Android SDK methods in the example code. Full documentation for these methods are available [here](http://docs.chirp.io/release/android/).\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Installing the Android SDK\"\n}\n[/block]\nThe Chirp Android SDK is distributed as an **.aar** file. You will have received this as part of the **developer pack**.\n[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"Android SDK\",\n  \"body\": \"To download the SDK you will need to create an account [here](https://admin.chirp.io/sign_up/create_profile). Or if you already have an account, [sign in here](https://admin.chirp.io/login) for the link to download.\"\n}\n[/block]\nIn a file explorer (*not* Android Studio), drag the **chirp-sdk-**version**.aar** into the */app/libs* directory in your project's root directory. \n\n## Modify build.gradle file\n\n\nNext, you will need to edit your *build.gradle* file. In Android Studio, locate the *project* tool window, then find the *Gradle Scripts* section. Open the main *build.gradle* file (which may also be labelled Module: app).  \n\nAdd the following highlighted lines to the *build.gradle* file:\n[block:html]\n{\n  \"html\": \"<div style=\\\"width:100%; height:100%; padding: 10px; border:1px solid black; \\\">\\n\\napply plugin: 'com.android.application'\\n<br>\\n<br>\\nandroid { <br>\\n&nbsp;&nbsp;&nbsp;compileSdkVersion 23 <br>\\n&nbsp;&nbsp;&nbsp;buildToolsVersion \\\"23.0.2\\\" <br>\\n<br>\\n&nbsp;&nbsp;&nbsp;&nbsp;defaultConfig { <br>\\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;applicationId \\\"io.chirp.gemswap\\\" <br>\\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;minSdkVersion 15 <br>\\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;targetSdkVersion 23 <br>\\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;versionCode 1 <br>\\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;versionName \\\"0.1.0\\\" <br>\\n&nbsp;&nbsp;&nbsp;} <br>\\n<br> \\n&nbsp;&nbsp;&nbsp;buildTypes { <br> \\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;release { <br> \\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;minifyEnabled false <br> \\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;proguardFiles <br>  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' <br> \\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} <br> \\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;debug { <br> \\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} <br>\\n&nbsp;&nbsp;&nbsp;} <br>\\n} <br>\\n<br><span style=\\\"color: #ff0000;\\\">\\nrepositories { <br>\\n\\n&nbsp;&nbsp;&nbsp;\\nflatDir { <br>\\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dirs 'libs' <br>\\n&nbsp;&nbsp;&nbsp;} <br>  \\n\\n}</span> <br>\\n<br> \\ndependencies { <br><br>\\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// The Chirp SDK library (ensure the version number matches your distribution): <br>\\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\\n<span style=\\\"color: #ff0000;\\\">compile 'io.chirp.sdk:chirp-sdk-release:2.5.2:::at:::aar' \\n</span>\\n<br>  \\n<br>\\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// The following dependencies need adding: <br>\\n<span style=\\\"color: #ff0000;\\\">\\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;compile 'com.squareup.retrofit2:retrofit:2.3.0' <br>\\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;compile 'com.squareup.retrofit2:converter-gson:2.3.0' <br>\\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;compile 'joda-time:joda-time:2.3' <br>\\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;compile 'com.j256.ormlite:ormlite-core:4.48' <br>\\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;compile 'com.j256.ormlite:ormlite-android:4.48' <br>\\n </span>\\n <br>  \\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// All other dependencies for your app should also be here: <br>\\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;compile 'com.android.support:appcompat-v7:23.1.1' <br>\\n} <br>\\n\\n</div>\\n\"\n}\n[/block]\nThe values you provide in the code above (*buildToolsVersion*, *applicationId*, and the **aar** file version) must match the particulars of your installations. \n\nDon’t forget to add the *flatDir* entry to the *repositories* section. Otherwise Gradle will not be able to locate the aar.\n\nAfter doing this, in Android Studio, select **Tools** > **Android** > **Sync Project with Gradle Files.** You should now have no error messages in the messages pane. If you still have error messages, troubleshoot the problem before continuing.\n\n## Update Android Manifest file\n\n\nFinally, you will need to update the Applications Manifest file. Open the */app/src/main/AndroidManifest.xml* file and add the following permissions (to the <manifest> block):\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<uses-permission android:name=\\\"android.permission.MODIFY_AUDIO_SETTINGS\\\"/>\\n<uses-permission android:name=\\\"android.permission.RECORD_AUDIO\\\"/>\\n<uses-permission android:name=\\\"android.permission.INTERNET\\\"/>\\n<uses-permission android:name=\\\"android.permission.ACCESS_NETWORK_STATE\\\"/>\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Basic setup\"\n}\n[/block]\nTo begin, add the following imports:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"import io.chirp.sdk.*;\\nimport io.chirp.sdk.model.*;\\nimport io.chirp.sdk.result.*;\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"App Key & Secret\",\n  \"body\": \"If you do not yet have an account with your key and secret please register [here](https://admin.chirp.io/sign-up).\"\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"ChirpSDK chirpSDK = new ChirpSDK(context, API_KEY, API_SECRET, new ChirpSDKStatusListener() {\\n      \\n    @Override\\n    public void onAuthenticationSuccess() {\\n\\n    }\\n\\n    @Override\\n    public void onChirpError(ChirpError chirpError) {\\n\\n    }\\n});\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\nThe app key and app secret identify your chirp-enabled app and allows your account to track per-chirp usage and behaviour across your install base.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Start listening for Chirps\"\n}\n[/block]\nTo listen for Chirps, first set up a listener as follows:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"chirpSDK.setListener(new ChirpSDKListener() {\\n\\n    @Override\\n    public void onChirpHeard(Chirp chirp) {\\n\\n    }\\n  \\n  \\t@Override\\n    public void onChirpHearStarted() {\\n\\n    }\\n\\n    @Override\\n    public void onChirpHearFailed() {\\n\\n    }\\n\\n    @Override\\n    public void onChirpError(ChirpError chirpError) {\\n\\n    }\\n});\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\nThen start audio processing with the following:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"chirpSDK.start();\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\nWhen the device hears a Chirp, the *onChirpHeard(Chirp)* callback method will be triggered. Any errors will be returned via *onChirpError(ChirpError)*.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Stop listening\"\n}\n[/block]\nStop audio processing with the following:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"chirpSDK.stop();\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Start Chirping\"\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"Online & Offline Chirps\",\n  \"body\": \"Read more about the difference between online and offline modes [here](http://dev.chirp.io/v1/docs/online-and-offline-operation)\"\n}\n[/block]\n## Play a Chirp\n\nYou can play a Chirp as follows:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"chirpSDK.chirp(new Chirp(\\\"parrotbill\\\"));\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"\",\n  \"body\": \"You must call start() before you call the chirp() method\"\n}\n[/block]\n## Create a Chirp\n\nCreate a unique Chirp when you need to send larger amounts of complex JSON-structured data.\n\nCreate your JSON using Android's inbuilt JSONObject type:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"JSONObject jsonObj = new JSONObject();\\njsonObj.put(\\\"key\\\", \\\"value\\\");\\njsonObj.put(\\\"more\\\", \\\"data\\\");\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\nPass the JSON into the Chirp object constructor:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Chirp chirp = new Chirp(jsonObj);\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\nNext, encode the Chirp by calling the method *create(Chirp)* \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"chirpSDK.create(chirp, new CallbackCreate() {\\n\\n    @Override\\n    public void onCreateResponse(Chirp chirp) {\\n    }\\n\\n    @Override\\n    public void onCreateError(ChirpError chirpError) {\\n\\n    }\\n});\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\nThe Chirp Chirp will be received via the *onCreateResponse(Chirp)* callback method. Any errors will be returned via *onCreateError(ChirpError)*.\n\n## Read a Chirp\n\nYou can read a Chirp by calling the method *read(Chirp)*. Demonstrated as follows:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"chirpSDK.read(chirp, new CallbackRead() {\\n\\n    @Override\\n    public void onReadResponse(Chirp chirp) {\\n\\n    }\\n\\n    @Override\\n    public void onReadError(ChirpError chirpError) {\\n\\n    }\\n});\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\nThe Chirp will be received via the *onReadResponse(Chirp)* callback method. Any errors will be returned via *onReadError(ChirpError)*.\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Common SDK Pitfalls\"\n}\n[/block]\n## Marshmallow Permissions\n\nAndroid Marshmallow allows users to toggle apps permissions at run time. Also by default, some permissions will be disabled when the app starts up for the first time. \n\nThe RECORD_AUDIO permission, which is fundamental in the use of Chirp, is an example of this. Therefore, it is important to check your app has RECORD_AUDIO permissions every time it is brought to the foreground. \n\nWe recommend using the android lifecycle methods, *onResume()* and *onPause()* to detect permissions and to trigger start and stopping listening. See the following: \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"@Override\\nprotected void onResume() {\\n  super.onResume();\\n\\n\\tif (ContextCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) {\\n\\tActivityCompat.requestPermissions(this, new String[] {Manifest.permission.RECORD_AUDIO}, RESULT_REQUEST_RECORD_AUDIO);\\n\\t}\\n\\telse {\\n\\t\\tchirpSDK.start();\\n  }\\n}\\n\\n@Override\\npublic void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {\\n\\tswitch (requestCode) {\\n\\t\\tcase RESULT_REQUEST_RECORD_AUDIO: {\\n\\t\\t\\tif (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {\\n\\t\\t\\t\\tchirpSDK.start();\\n\\t\\t\\t}\\n      \\treturn;\\n    }\\n  }\\n}\\n\\n@Override\\nprotected void onPause() {\\n\\tsuper.onPause();\\n  chirpSDK.stop();\\n}\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n## Valid Identifiers\n\nTypically an identifier must be 10 characters in length. \n\nThe SDK contains helper methods for checking if an identifier is valid and generating a random valid identifier for testing and debug purposes.\n\nTo check if an identifier is valid:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"boolean valid = ChirpSDKHelpers.isValidIdentifier(\\\"parrotbill\\\"); \",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\nTo generate a random valid identifier:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"String identifier = ChirpSDKHelpers.generateRandomIdentifier();\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]","excerpt":"Using the Chirp Android SDK for mobile and tablet.","slug":"chirp-for-android","type":"basic","title":"Chirp for Android"}

Chirp for Android

Using the Chirp Android SDK for mobile and tablet.

The Chirp Android SDK is designed to get your Android devices Chirping quickly and easily. This guide will lead you through the steps required to get your App Chirping. We will show you how to: * Install the Chirp SDK * Setup the Chirp SDK * Start Chirping We will be calling several of the Chirp Android SDK methods in the example code. Full documentation for these methods are available [here](http://docs.chirp.io/release/android/). [block:api-header] { "type": "basic", "title": "Installing the Android SDK" } [/block] The Chirp Android SDK is distributed as an **.aar** file. You will have received this as part of the **developer pack**. [block:callout] { "type": "info", "title": "Android SDK", "body": "To download the SDK you will need to create an account [here](https://admin.chirp.io/sign_up/create_profile). Or if you already have an account, [sign in here](https://admin.chirp.io/login) for the link to download." } [/block] In a file explorer (*not* Android Studio), drag the **chirp-sdk-**version**.aar** into the */app/libs* directory in your project's root directory. ## Modify build.gradle file Next, you will need to edit your *build.gradle* file. In Android Studio, locate the *project* tool window, then find the *Gradle Scripts* section. Open the main *build.gradle* file (which may also be labelled Module: app). Add the following highlighted lines to the *build.gradle* file: [block:html] { "html": "<div style=\"width:100%; height:100%; padding: 10px; border:1px solid black; \">\n\napply plugin: 'com.android.application'\n<br>\n<br>\nandroid { <br>\n&nbsp;&nbsp;&nbsp;compileSdkVersion 23 <br>\n&nbsp;&nbsp;&nbsp;buildToolsVersion \"23.0.2\" <br>\n<br>\n&nbsp;&nbsp;&nbsp;&nbsp;defaultConfig { <br>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;applicationId \"io.chirp.gemswap\" <br>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;minSdkVersion 15 <br>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;targetSdkVersion 23 <br>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;versionCode 1 <br>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;versionName \"0.1.0\" <br>\n&nbsp;&nbsp;&nbsp;} <br>\n<br> \n&nbsp;&nbsp;&nbsp;buildTypes { <br> \n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;release { <br> \n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;minifyEnabled false <br> \n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;proguardFiles <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' <br> \n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} <br> \n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;debug { <br> \n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} <br>\n&nbsp;&nbsp;&nbsp;} <br>\n} <br>\n<br><span style=\"color: #ff0000;\">\nrepositories { <br>\n\n&nbsp;&nbsp;&nbsp;\nflatDir { <br>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dirs 'libs' <br>\n&nbsp;&nbsp;&nbsp;} <br> \n\n}</span> <br>\n<br> \ndependencies { <br><br>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// The Chirp SDK library (ensure the version number matches your distribution): <br>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n<span style=\"color: #ff0000;\">compile 'io.chirp.sdk:chirp-sdk-release:2.5.2@aar' \n</span>\n<br> \n<br>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// The following dependencies need adding: <br>\n<span style=\"color: #ff0000;\">\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;compile 'com.squareup.retrofit2:retrofit:2.3.0' <br>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;compile 'com.squareup.retrofit2:converter-gson:2.3.0' <br>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;compile 'joda-time:joda-time:2.3' <br>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;compile 'com.j256.ormlite:ormlite-core:4.48' <br>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;compile 'com.j256.ormlite:ormlite-android:4.48' <br>\n </span>\n <br> \n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// All other dependencies for your app should also be here: <br>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;compile 'com.android.support:appcompat-v7:23.1.1' <br>\n} <br>\n\n</div>\n" } [/block] The values you provide in the code above (*buildToolsVersion*, *applicationId*, and the **aar** file version) must match the particulars of your installations. Don’t forget to add the *flatDir* entry to the *repositories* section. Otherwise Gradle will not be able to locate the aar. After doing this, in Android Studio, select **Tools** > **Android** > **Sync Project with Gradle Files.** You should now have no error messages in the messages pane. If you still have error messages, troubleshoot the problem before continuing. ## Update Android Manifest file Finally, you will need to update the Applications Manifest file. Open the */app/src/main/AndroidManifest.xml* file and add the following permissions (to the <manifest> block): [block:code] { "codes": [ { "code": "<uses-permission android:name=\"android.permission.MODIFY_AUDIO_SETTINGS\"/>\n<uses-permission android:name=\"android.permission.RECORD_AUDIO\"/>\n<uses-permission android:name=\"android.permission.INTERNET\"/>\n<uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\"/>", "language": "java" } ] } [/block] [block:api-header] { "type": "basic", "title": "Basic setup" } [/block] To begin, add the following imports: [block:code] { "codes": [ { "code": "import io.chirp.sdk.*;\nimport io.chirp.sdk.model.*;\nimport io.chirp.sdk.result.*;", "language": "java" } ] } [/block] [block:callout] { "type": "info", "title": "App Key & Secret", "body": "If you do not yet have an account with your key and secret please register [here](https://admin.chirp.io/sign-up)." } [/block] [block:code] { "codes": [ { "code": "ChirpSDK chirpSDK = new ChirpSDK(context, API_KEY, API_SECRET, new ChirpSDKStatusListener() {\n \n @Override\n public void onAuthenticationSuccess() {\n\n }\n\n @Override\n public void onChirpError(ChirpError chirpError) {\n\n }\n});", "language": "java" } ] } [/block] The app key and app secret identify your chirp-enabled app and allows your account to track per-chirp usage and behaviour across your install base. [block:api-header] { "type": "basic", "title": "Start listening for Chirps" } [/block] To listen for Chirps, first set up a listener as follows: [block:code] { "codes": [ { "code": "chirpSDK.setListener(new ChirpSDKListener() {\n\n @Override\n public void onChirpHeard(Chirp chirp) {\n\n }\n \n \t@Override\n public void onChirpHearStarted() {\n\n }\n\n @Override\n public void onChirpHearFailed() {\n\n }\n\n @Override\n public void onChirpError(ChirpError chirpError) {\n\n }\n});", "language": "java" } ] } [/block] Then start audio processing with the following: [block:code] { "codes": [ { "code": "chirpSDK.start();", "language": "java" } ] } [/block] When the device hears a Chirp, the *onChirpHeard(Chirp)* callback method will be triggered. Any errors will be returned via *onChirpError(ChirpError)*. [block:api-header] { "type": "basic", "title": "Stop listening" } [/block] Stop audio processing with the following: [block:code] { "codes": [ { "code": "chirpSDK.stop();", "language": "java" } ] } [/block] [block:api-header] { "type": "basic", "title": "Start Chirping" } [/block] [block:callout] { "type": "info", "title": "Online & Offline Chirps", "body": "Read more about the difference between online and offline modes [here](http://dev.chirp.io/v1/docs/online-and-offline-operation)" } [/block] ## Play a Chirp You can play a Chirp as follows: [block:code] { "codes": [ { "code": "chirpSDK.chirp(new Chirp(\"parrotbill\"));", "language": "java" } ] } [/block] [block:callout] { "type": "info", "title": "", "body": "You must call start() before you call the chirp() method" } [/block] ## Create a Chirp Create a unique Chirp when you need to send larger amounts of complex JSON-structured data. Create your JSON using Android's inbuilt JSONObject type: [block:code] { "codes": [ { "code": "JSONObject jsonObj = new JSONObject();\njsonObj.put(\"key\", \"value\");\njsonObj.put(\"more\", \"data\");", "language": "java" } ] } [/block] Pass the JSON into the Chirp object constructor: [block:code] { "codes": [ { "code": "Chirp chirp = new Chirp(jsonObj);", "language": "java" } ] } [/block] Next, encode the Chirp by calling the method *create(Chirp)* [block:code] { "codes": [ { "code": "chirpSDK.create(chirp, new CallbackCreate() {\n\n @Override\n public void onCreateResponse(Chirp chirp) {\n }\n\n @Override\n public void onCreateError(ChirpError chirpError) {\n\n }\n});", "language": "java" } ] } [/block] The Chirp Chirp will be received via the *onCreateResponse(Chirp)* callback method. Any errors will be returned via *onCreateError(ChirpError)*. ## Read a Chirp You can read a Chirp by calling the method *read(Chirp)*. Demonstrated as follows: [block:code] { "codes": [ { "code": "chirpSDK.read(chirp, new CallbackRead() {\n\n @Override\n public void onReadResponse(Chirp chirp) {\n\n }\n\n @Override\n public void onReadError(ChirpError chirpError) {\n\n }\n});", "language": "java" } ] } [/block] The Chirp will be received via the *onReadResponse(Chirp)* callback method. Any errors will be returned via *onReadError(ChirpError)*. [block:api-header] { "type": "basic", "title": "Common SDK Pitfalls" } [/block] ## Marshmallow Permissions Android Marshmallow allows users to toggle apps permissions at run time. Also by default, some permissions will be disabled when the app starts up for the first time. The RECORD_AUDIO permission, which is fundamental in the use of Chirp, is an example of this. Therefore, it is important to check your app has RECORD_AUDIO permissions every time it is brought to the foreground. We recommend using the android lifecycle methods, *onResume()* and *onPause()* to detect permissions and to trigger start and stopping listening. See the following: [block:code] { "codes": [ { "code": "@Override\nprotected void onResume() {\n super.onResume();\n\n\tif (ContextCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) {\n\tActivityCompat.requestPermissions(this, new String[] {Manifest.permission.RECORD_AUDIO}, RESULT_REQUEST_RECORD_AUDIO);\n\t}\n\telse {\n\t\tchirpSDK.start();\n }\n}\n\n@Override\npublic void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {\n\tswitch (requestCode) {\n\t\tcase RESULT_REQUEST_RECORD_AUDIO: {\n\t\t\tif (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {\n\t\t\t\tchirpSDK.start();\n\t\t\t}\n \treturn;\n }\n }\n}\n\n@Override\nprotected void onPause() {\n\tsuper.onPause();\n chirpSDK.stop();\n}", "language": "java" } ] } [/block] ## Valid Identifiers Typically an identifier must be 10 characters in length. The SDK contains helper methods for checking if an identifier is valid and generating a random valid identifier for testing and debug purposes. To check if an identifier is valid: [block:code] { "codes": [ { "code": "boolean valid = ChirpSDKHelpers.isValidIdentifier(\"parrotbill\"); ", "language": "java" } ] } [/block] To generate a random valid identifier: [block:code] { "codes": [ { "code": "String identifier = ChirpSDKHelpers.generateRandomIdentifier();", "language": "java" } ] } [/block]