{"_id":"58c6a6bbebb6c70f003483e9","user":"5770dd042659e20e00c90a98","version":{"_id":"574ff4bd3fa1870e00889ba9","project":"574ff4bd3fa1870e00889ba6","__v":25,"createdAt":"2016-06-02T08:56:29.492Z","releaseDate":"2016-06-02T08:56:29.492Z","categories":["574ff4bd3fa1870e00889baa","577278ecdceb570e003a9001","577279865617b117009e643f","577279985617b117009e6440","577279bc8c48e00e00503504","5774fe18605b770e0037be8a","577ce3ad87acf617003c4187","577f8476a77c700e006a6c52","57b486ae0d2b640e00e9d3f5","57b722133d3e620e004ec74b","57bd95f00fe3a00e003e2cc5","57c8349359cd4b0e00b888ef","57c8349b5754fa1700b12242","57cedb0bad483e0e00890239","57cedbe807d7ea0e00e438cc","57d82967156ef72b007ffcd8","58ee353ad1ee2f0f0034a13d","596623221738df00298622a5","59a51730192dba000fc9ca38","59a8129f1e7b26000fa0fb1a","5a0322bf044b6f001c236e36","5a79897c5b6e430030746df6","5a79898c2b2d5f0012cbab63","5ab3b5e3d2d1e2006252a8f2","5b1a43bd678eab0003aa54a4"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"3.0.0","version":"3.0"},"__v":0,"parentDoc":null,"category":{"_id":"57b486ae0d2b640e00e9d3f5","__v":0,"project":"574ff4bd3fa1870e00889ba6","version":"574ff4bd3fa1870e00889ba9","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2016-08-17T15:45:50.062Z","from_sync":false,"order":7,"slug":"native-ads-mediation-layer","title":"Android SDK"},"project":"574ff4bd3fa1870e00889ba6","updates":[],"next":{"pages":[],"description":""},"createdAt":"2017-03-13T14:03:39.816Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":true,"api":{"settings":"","results":{"codes":[]},"auth":"required","params":[],"url":""},"isReference":false,"order":6,"body":"This document facilitates the integration of Mediation Layer Android SDK.  There are four integration types for developers:\n* [Native](http://developers.pubnative.net/docs/ad-layouts)\n* [Small Ad Layout](http://developers.pubnative.net/docs/standard-ad-layouts)\n* [Medium Ad Layout](http://developers.pubnative.net/docs/medium-ad-layouts) \n* [Large Ad Layout](http://developers.pubnative.net/docs/large-ad-layouts)\n\nFor more detailed documentation, please refer to our github documentation (linked above).\n[block:api-header]\n{\n  \"title\": \"Integration samples project\"\n}\n[/block]\nHere you can find a collection of most common pubnative SDK [integration examples for Android](https://github.com/pubnative/pubnative-android-integration-examples).\n[block:api-header]\n{\n  \"title\": \"Requirements\"\n}\n[/block]\n* Android API 15 or greater\n* An App Token provided in PubNative Dashboard.\n* A Placement Name configured in the PubNative Dashboard.\n[block:api-header]\n{\n  \"title\": \"Permissions\"\n}\n[/block]\nAdd the following permissions to your application manifest file.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<uses-permission android:name=\\\"android.permission.INTERNET\\\"/>\\n<uses-permission android:name=\\\"android.permission.ACCESS_NETWORK_STATE\\\"/>\",\n      \"language\": \"xml\"\n    }\n  ]\n}\n[/block]\nOptionally but necessary for better tracking, you can add one of them or both location permisssion\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<uses-permission android:name=\\\"android.permission.ACCESS_COARSE_LOCATION\\\"/>\",\n      \"language\": \"xml\"\n    }\n  ]\n}\n[/block]\nor\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<uses-permission android:name=\\\"android.permission.ACCESS_FINE_LOCATION\\\" />\",\n      \"language\": \"xml\"\n    }\n  ]\n}\n[/block]\n*Note*: If you are using both NETWORK_PROVIDER and GPS_PROVIDER, then you need to request only the ACCESS_FINE_LOCATION permission, because it includes permission for both providers. (Permission for ACCESS_COARSE_LOCATION includes permission only for NETWORK_PROVIDER).\n[block:api-header]\n{\n  \"title\": \"Install Pubnative SDK\"\n}\n[/block]\n**Gradle**\n\nThe PubNative Mediation SDK is available via jCenter. To add the sdk dependency, open your project's build.gradle and update the repositories and dependencies blocks as follows:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"repositories {\\n    // ... other project repositories\\n    jcenter()\\n}\\n\\n// ...\\n\\ndependencies {\\n    // ... other project dependencies\\n    compile 'net.pubnative:sdk:2.0.12'\\n}\",\n      \"language\": \"groovy\"\n    }\n  ]\n}\n[/block]\n**Jar**\n\nDownload jar from here and add it into your app.  \n\n*How to add jar in Android studio*\n\n* Copy the jar file from where you downloaded it.\n* paste it in `libs` folder.\n* open build.gradle.\n* add lines under dependencies as:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"compile fileTree(dir: 'libs', include: ['*.jar'])\",\n      \"language\": \"groovy\"\n    }\n  ]\n}\n[/block]\n**Manual**\n\nClone the repository and import the `:sdk` project into your app.\n[block:api-header]\n{\n  \"title\": \"ProGuard\"\n}\n[/block]\nObfuscation protects an application from reverse-engineering or modification by making it harder for a third-party to access your source (decompiled) code.\n\n*PubNative SDK is already obfuscated* Therefore, if you did not obfuscate your application using `ProGuard™`, then you can skip this step. If you have obfuscated your application using ProGuard, then you need to add these lines in the ProGuard configuration file:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"-keepattributes Signature\\n-keep class net.pubnative.** { *; }\",\n      \"language\": \"groovy\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"title\": \"Configure SDK\"\n}\n[/block]\nThere are certain parameters that should be configured in the SDK before doing any type of interaction with It. Ensure to configure this parameters only 1 per session.\n\nIf you are doing tests:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Pubnative.setTestMode(boolean);\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\nIf your app is COPPA compliant:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Pubnative.setCoppaMode(boolean);\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\nIf you want to improve targeting, first configure the PNAdTargetingModel object that you want to give away and then invoke the following method:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Pubnative.setTargeting(PNAdTargetingModel);\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n## Initialise SDK\n\nIn order to initialise request you must call init() before requesting for ads.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Pubnative.init(<CONTEXT>, \\\"<YOUR_APP_TOKEN_HERE>\\\");\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]","excerpt":"","slug":"for-developers","type":"basic","title":"For Developers"}
This document facilitates the integration of Mediation Layer Android SDK. There are four integration types for developers: * [Native](http://developers.pubnative.net/docs/ad-layouts) * [Small Ad Layout](http://developers.pubnative.net/docs/standard-ad-layouts) * [Medium Ad Layout](http://developers.pubnative.net/docs/medium-ad-layouts) * [Large Ad Layout](http://developers.pubnative.net/docs/large-ad-layouts) For more detailed documentation, please refer to our github documentation (linked above). [block:api-header] { "title": "Integration samples project" } [/block] Here you can find a collection of most common pubnative SDK [integration examples for Android](https://github.com/pubnative/pubnative-android-integration-examples). [block:api-header] { "title": "Requirements" } [/block] * Android API 15 or greater * An App Token provided in PubNative Dashboard. * A Placement Name configured in the PubNative Dashboard. [block:api-header] { "title": "Permissions" } [/block] Add the following permissions to your application manifest file. [block:code] { "codes": [ { "code": "<uses-permission android:name=\"android.permission.INTERNET\"/>\n<uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\"/>", "language": "xml" } ] } [/block] Optionally but necessary for better tracking, you can add one of them or both location permisssion [block:code] { "codes": [ { "code": "<uses-permission android:name=\"android.permission.ACCESS_COARSE_LOCATION\"/>", "language": "xml" } ] } [/block] or [block:code] { "codes": [ { "code": "<uses-permission android:name=\"android.permission.ACCESS_FINE_LOCATION\" />", "language": "xml" } ] } [/block] *Note*: If you are using both NETWORK_PROVIDER and GPS_PROVIDER, then you need to request only the ACCESS_FINE_LOCATION permission, because it includes permission for both providers. (Permission for ACCESS_COARSE_LOCATION includes permission only for NETWORK_PROVIDER). [block:api-header] { "title": "Install Pubnative SDK" } [/block] **Gradle** The PubNative Mediation SDK is available via jCenter. To add the sdk dependency, open your project's build.gradle and update the repositories and dependencies blocks as follows: [block:code] { "codes": [ { "code": "repositories {\n // ... other project repositories\n jcenter()\n}\n\n// ...\n\ndependencies {\n // ... other project dependencies\n compile 'net.pubnative:sdk:2.0.12'\n}", "language": "groovy" } ] } [/block] **Jar** Download jar from here and add it into your app. *How to add jar in Android studio* * Copy the jar file from where you downloaded it. * paste it in `libs` folder. * open build.gradle. * add lines under dependencies as: [block:code] { "codes": [ { "code": "compile fileTree(dir: 'libs', include: ['*.jar'])", "language": "groovy" } ] } [/block] **Manual** Clone the repository and import the `:sdk` project into your app. [block:api-header] { "title": "ProGuard" } [/block] Obfuscation protects an application from reverse-engineering or modification by making it harder for a third-party to access your source (decompiled) code. *PubNative SDK is already obfuscated* Therefore, if you did not obfuscate your application using `ProGuard™`, then you can skip this step. If you have obfuscated your application using ProGuard, then you need to add these lines in the ProGuard configuration file: [block:code] { "codes": [ { "code": "-keepattributes Signature\n-keep class net.pubnative.** { *; }", "language": "groovy" } ] } [/block] [block:api-header] { "title": "Configure SDK" } [/block] There are certain parameters that should be configured in the SDK before doing any type of interaction with It. Ensure to configure this parameters only 1 per session. If you are doing tests: [block:code] { "codes": [ { "code": "Pubnative.setTestMode(boolean);", "language": "java" } ] } [/block] If your app is COPPA compliant: [block:code] { "codes": [ { "code": "Pubnative.setCoppaMode(boolean);", "language": "java" } ] } [/block] If you want to improve targeting, first configure the PNAdTargetingModel object that you want to give away and then invoke the following method: [block:code] { "codes": [ { "code": "Pubnative.setTargeting(PNAdTargetingModel);", "language": "java" } ] } [/block] ## Initialise SDK In order to initialise request you must call init() before requesting for ads. [block:code] { "codes": [ { "code": "Pubnative.init(<CONTEXT>, \"<YOUR_APP_TOKEN_HERE>\");", "language": "java" } ] } [/block]