{"__v":0,"_id":"588f722cbcace50f0052ba18","category":{"version":"588f722bbcace50f0052b9e1","project":"565f5fa26bafd40d0030a064","_id":"588f722bbcace50f0052b9e5","__v":0,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2016-02-18T20:31:28.395Z","from_sync":false,"order":3,"slug":"sdks","title":"Client SDKs"},"parentDoc":null,"project":"565f5fa26bafd40d0030a064","user":"565f5f29de5dc50d00acfe9f","version":{"__v":1,"_id":"588f722bbcace50f0052b9e1","project":"565f5fa26bafd40d0030a064","createdAt":"2017-01-30T17:04:43.410Z","releaseDate":"2017-01-30T17:04:43.410Z","categories":["588f722bbcace50f0052b9e2","588f722bbcace50f0052b9e3","588f722bbcace50f0052b9e4","588f722bbcace50f0052b9e5","588f722bbcace50f0052b9e6","588f722bbcace50f0052b9e7"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"5.3.0","version":"5.3.0"},"updates":["57e54b14685f7c19007fba3c","57ea8c201780cd170064f281"],"next":{"pages":[],"description":""},"createdAt":"2016-02-19T13:48:09.180Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":2,"body":"The nanoscale.io Android SDK is a lightweight SDK written for Android devices. It supports Android versions 9 and up. You can view the source <a href=\"https://github.com/nanoscaleio/justapis-android-sdk\" target=\"_blank\">here on GitHub</a>.\n\n## Dependencies\n\nThese dependencies needed are:\n\n* GSON: compile 'com.google.code.gson:gson:2.5'\n* Guava: compile 'com.google.guava:guava:18.0'\n* OKHttp: compile 'com.squareup.okhttp:okhttp:2.7.4'\n\nAP's nanoscale.io Java core library:\nAPGW-[version]-SNAPSHOT.jar\n\n\n## Introduction\n\nThe main class to work with is APAndroidGateway. You will use an instance of this class to make requests.\n\nAn instance should be created using a builder. A 'Context' is needed as well. You will want to use the application's\nApplication context. This is needed because it utilizes Android volley and it's needed to construct a request queue\nand cache.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"APAndroidGateway.Builder builder = new APAndroidGateway.Builder();\\nbuilder.url(\\\"http://foo.lvh.me:3000/api/v1/foo\\\");\\n\\n// Provide the application  context and build the gateway object\\nAPAndroidGateway gw = builder.build(getActivity().getApplication());\",\n      \"language\": \"java\",\n      \"name\": \"Create APGW\"\n    }\n  ]\n}\n[/block]\nResponse caching is supported and the cache files are written to disk when enabled.\n\n## Setup\n\nThis is a setup instruction for an Android Studio project. Unzip the archive and place APGW-[version]-SNAPSHOT>.jar and gw-[version].aar in the libs folder of your application.\n\nModify your gradle.build with:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"dependencies {\\n\\n    compile(name:'gw-debug', ext:'aar')\\n    compile 'com.google.guava:guava:18.0'\\n    compile 'com.google.code.gson:gson:2.5'\\n    compile 'com.squareup.okhttp:okhttp:2.7.4'\\n\\n}\",\n      \"language\": \"java\",\n      \"name\": \"Dependencies\"\n    }\n  ]\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"repositories {\\n    flatDir {\\n        dirs 'libs'\\n    }\\n}\",\n      \"language\": \"java\",\n      \"name\": \"Repositories\"\n    }\n  ]\n}\n[/block]\nEnable internet access in your AndroidManfiest.xml\n\n<uses-permission android:name=\"android.permission.INTERNET\"/>\n\n## Examples\n\n### Basic Usage\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"APAndroidGateway.Builder builder = new APAndroidGateway.Builder();\\nbuilder.url(\\\"http://foo.lvh.me:3000/api/v1/foo\\\");\\n\\nAPAndroidGateway gw = builder.build(getActivity().getApplication());\\n\\ngw.setBody(\\\"{'foo':'bar'}\\\");\\n\\ngw.post(\\\"/bar\\\");\\n\\nResponseFromRequest result = gw.readResponse();\\n\\n// Access response body\\nSystem.out.println(result.data)\",\n      \"language\": \"java\",\n      \"name\": \"Send a POST request synchronously\"\n    }\n  ]\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"APAndroidGateway.Builder builder = new APAndroidGateway.Builder();\\nbuilder.url(\\\"http://localhost:3000\\\");\\n\\nAPAndroidGateway gw = builder.build(getActivity().getApplication());\\n\\ngw.get(\\\"/api/v1/foo\\\", new APAndroidStringCallback() {\\n\\n  :::at:::Override\\n  public void finished(String result, Throwable ex) {\\n      if (ex == null) {\\n          System.out.println(\\\"Got results: \\\" + result);\\n      } else {\\n          ex.printStackTrace();\\n      }\\n  }\\n\\n});\",\n      \"language\": \"java\",\n      \"name\": \"Send a request asynchronously\"\n    }\n  ]\n}\n[/block]\n### Certificate Pinning\n\nCertificate pinning allows you to tie certificates against specified domains. It defends against attacks on certificate authorities.\nIt has it's limitations as well. We require the base64 encoded hashed SubjectPublicKeyInfo. See the example below for google.com:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"APAndroidGateway.getCertPinningManager().add(\\\"google.com\\\", \\\"sha1/qANMQh2fy6tyyjS9qEjosxOLe1w=\\\");\\nAPAndroidGateway gw = new APAndroidGateway.Builder().url(\\\"https://google.com\\\").build(this.getActivity());\\n\\ngw.setUseCertPinning(true);\\n\\nAPGateway gw = builder.build(getActivity().getApplication());\\ngw.post(\\\"/bar\\\");\",\n      \"language\": \"java\",\n      \"name\": \"Certificate pinning\"\n    }\n  ]\n}\n[/block]\n### Caching\n\nEnable caching of the request:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"APAndroidGateway.Builder builder = new APAndroidGateway.Builder();\\nbuilder.url(\\\"http://localhost:3000\\\");\\n\\nAPAndroidGateway gw = builder.build(getActivity().getApplication());\\n\\n// Enable caching\\ngw.useCaching(true).get(\\\"/api/v1/foo\\\", new APAndroidStringCallback() {\\n\\n  @Override\\n  public void finished(String result, Throwable ex) {\\n      if (ex == null) {\\n          System.out.println(\\\"Got results: \\\" + result);\\n      } else {\\n          ex.printStackTrace();\\n      }\\n  }\\n\\n});\",\n      \"language\": \"java\",\n      \"name\": \"Request caching\"\n    }\n  ]\n}\n[/block]\nThe next request to the same url endpoint will not hit the network.","excerpt":"","slug":"android","type":"basic","title":"Android"}
The nanoscale.io Android SDK is a lightweight SDK written for Android devices. It supports Android versions 9 and up. You can view the source <a href="https://github.com/nanoscaleio/justapis-android-sdk" target="_blank">here on GitHub</a>. ## Dependencies These dependencies needed are: * GSON: compile 'com.google.code.gson:gson:2.5' * Guava: compile 'com.google.guava:guava:18.0' * OKHttp: compile 'com.squareup.okhttp:okhttp:2.7.4' AP's nanoscale.io Java core library: APGW-[version]-SNAPSHOT.jar ## Introduction The main class to work with is APAndroidGateway. You will use an instance of this class to make requests. An instance should be created using a builder. A 'Context' is needed as well. You will want to use the application's Application context. This is needed because it utilizes Android volley and it's needed to construct a request queue and cache. [block:code] { "codes": [ { "code": "APAndroidGateway.Builder builder = new APAndroidGateway.Builder();\nbuilder.url(\"http://foo.lvh.me:3000/api/v1/foo\");\n\n// Provide the application context and build the gateway object\nAPAndroidGateway gw = builder.build(getActivity().getApplication());", "language": "java", "name": "Create APGW" } ] } [/block] Response caching is supported and the cache files are written to disk when enabled. ## Setup This is a setup instruction for an Android Studio project. Unzip the archive and place APGW-[version]-SNAPSHOT>.jar and gw-[version].aar in the libs folder of your application. Modify your gradle.build with: [block:code] { "codes": [ { "code": "dependencies {\n\n compile(name:'gw-debug', ext:'aar')\n compile 'com.google.guava:guava:18.0'\n compile 'com.google.code.gson:gson:2.5'\n compile 'com.squareup.okhttp:okhttp:2.7.4'\n\n}", "language": "java", "name": "Dependencies" } ] } [/block] [block:code] { "codes": [ { "code": "repositories {\n flatDir {\n dirs 'libs'\n }\n}", "language": "java", "name": "Repositories" } ] } [/block] Enable internet access in your AndroidManfiest.xml <uses-permission android:name="android.permission.INTERNET"/> ## Examples ### Basic Usage [block:code] { "codes": [ { "code": "APAndroidGateway.Builder builder = new APAndroidGateway.Builder();\nbuilder.url(\"http://foo.lvh.me:3000/api/v1/foo\");\n\nAPAndroidGateway gw = builder.build(getActivity().getApplication());\n\ngw.setBody(\"{'foo':'bar'}\");\n\ngw.post(\"/bar\");\n\nResponseFromRequest result = gw.readResponse();\n\n// Access response body\nSystem.out.println(result.data)", "language": "java", "name": "Send a POST request synchronously" } ] } [/block] [block:code] { "codes": [ { "code": "APAndroidGateway.Builder builder = new APAndroidGateway.Builder();\nbuilder.url(\"http://localhost:3000\");\n\nAPAndroidGateway gw = builder.build(getActivity().getApplication());\n\ngw.get(\"/api/v1/foo\", new APAndroidStringCallback() {\n\n @Override\n public void finished(String result, Throwable ex) {\n if (ex == null) {\n System.out.println(\"Got results: \" + result);\n } else {\n ex.printStackTrace();\n }\n }\n\n});", "language": "java", "name": "Send a request asynchronously" } ] } [/block] ### Certificate Pinning Certificate pinning allows you to tie certificates against specified domains. It defends against attacks on certificate authorities. It has it's limitations as well. We require the base64 encoded hashed SubjectPublicKeyInfo. See the example below for google.com: [block:code] { "codes": [ { "code": "APAndroidGateway.getCertPinningManager().add(\"google.com\", \"sha1/qANMQh2fy6tyyjS9qEjosxOLe1w=\");\nAPAndroidGateway gw = new APAndroidGateway.Builder().url(\"https://google.com\").build(this.getActivity());\n\ngw.setUseCertPinning(true);\n\nAPGateway gw = builder.build(getActivity().getApplication());\ngw.post(\"/bar\");", "language": "java", "name": "Certificate pinning" } ] } [/block] ### Caching Enable caching of the request: [block:code] { "codes": [ { "code": "APAndroidGateway.Builder builder = new APAndroidGateway.Builder();\nbuilder.url(\"http://localhost:3000\");\n\nAPAndroidGateway gw = builder.build(getActivity().getApplication());\n\n// Enable caching\ngw.useCaching(true).get(\"/api/v1/foo\", new APAndroidStringCallback() {\n\n @Override\n public void finished(String result, Throwable ex) {\n if (ex == null) {\n System.out.println(\"Got results: \" + result);\n } else {\n ex.printStackTrace();\n }\n }\n\n});", "language": "java", "name": "Request caching" } ] } [/block] The next request to the same url endpoint will not hit the network.