{"_id":"563b50349e3f2225009fd296","__v":70,"parentDoc":null,"version":{"_id":"5429beef1163360800ed31fd","__v":22,"project":"5429beef1163360800ed31fa","createdAt":"2014-09-29T20:19:59.904Z","releaseDate":"2014-09-29T20:19:59.904Z","categories":["5429beef1163360800ed31fe","55e74e1f5d36b32b002563fa","55e7500a73169617001f2e86","55e76b8196131b2f00bf4b72","55e89569cdbb8a350096df9c","55f8935eb089b71700a8364e","55f8a67d3bb4bb0d0022d093","55f9dbefc7ef770d00d9bf6d","5601c21a22ecf60d002b27b3","5601c21ff12aee0d001bb06e","5601c2256c7b610d00280db5","5601c22c22ecf60d002b27b4","5603738d0c78b00d0039af47","5626f70bfcbbc621004ebf52","566f7a1ae144ab0d00e9732f","566f85ca7820960d00c3b93d","56708ce43a32d20d00c45cbf","56708d436995210d003aad8e","5736471abe10a9200030732c","57a82c7aff9bd30e00a6f1c1","591b8500e3992319007190f4","5a3718305c66a60012d960ba"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"category":{"_id":"566f85ca7820960d00c3b93d","pages":[],"project":"5429beef1163360800ed31fa","version":"5429beef1163360800ed31fd","__v":0,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-12-15T03:15:22.182Z","from_sync":false,"order":3,"slug":"integrating-for-apps","title":"Integrating for Apps"},"project":"5429beef1163360800ed31fa","user":"563b4a20dfa1282b000dd262","updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-11-05T12:48:52.406Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":1,"body":"Welcome to Polymorph Android SDK documentation. Please check out the \"Getting Started\" section below before integrating your app with the SDK.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Getting Started\"\n}\n[/block]\nThis section explains the process of including Polymorph SDK in your Android application and setting dependencies.\n\n** Prerequisites and Dependencies **\n\n  * Android version 4.0.3 (API 15) and above\n\nAdd following to your build.gradle\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"dependencies {\\n    compile 'com.android.support:support-v4:22.2.1'\\n    compile 'com.android.support:appcompat-v7:22.2.1'\\n    compile 'com.android.support:recyclerview-v7:22.2.1'\\n    compile 'com.google.android.gms:play-services:7.8.0'\\n}\",\n      \"language\": \"groovy\"\n    }\n  ]\n}\n[/block]\n**Including Polymorph SDK in your Android project**\n\nClick [**here**](https://github.com/picatcha/adsnative-sdk-android/archive/master.zip) to download the SDK as zipped source. Extract **adsnative_sdk_2.0.0.aar** from <unzipped>/adsnative_sdk/ location and place it under your project's libs folder (create libs if not already done).\n\nAdd the compiled .aar to your build.gradle file as below.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"repositories {\\n    flatDir {\\n        dirs 'libs'\\n    }\\n}\\n// ...\\ndependencies {\\n    compile(name:'adsnative_sdk_2.0.0', ext:'aar')\\n}\",\n      \"language\": \"groovy\"\n    }\n  ]\n}\n[/block]\n**Required Permissions in Android Manifest**\nFollowing permissions are mandatory. Please add them to your AndroidManifest.xml 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]\n**Recommended Permissions in Android Manifest**\nWe recommend adding following permissions to your AndroidManifest.xml.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<uses-permission android:name=\\\"android.permission.ACCESS_COARSE_LOCATION\\\" />\\n<uses-permission android:name=\\\"android.permission.ACCESS_FINE_LOCATION\\\" />\",\n      \"language\": \"xml\"\n    }\n  ]\n}\n[/block]\n**ProGuard**\nPolymorph SDK is already obfuscated and minified using ProGuard. If you are running ProGuard on your Android application, please add the following to your ProGuard configuration file.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"-keep class com.adsnative.** { *; }\\n-dontwarn com.adsnative.**\",\n      \"language\": \"groovy\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Native Ads Integration\"\n}\n[/block]\nImport Polymorph SDK classes into your activity by adding the following line of code to the imports section of your activity class.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"import com.adsnative.ads.*;\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\nPolymorph SDK supports following ad formats. Depending on your requirement and the type of app you have, you can choose one of the below methods.\n\n  * [**Content Stream Ads**](https://dev.getpolymorph.com/docs/android-sdk#content-stream-ads) - These are ads that appear as part of a content stream. For Android, we support the RecyclerView and TableView/GridView layouts. If your app is using an adapter to show content stream then we highly recommend using this integration.\n  * [**Standard Integration (Single Native Ad)**](https://dev.getpolymorph.com/docs/android-sdk#standard-integration) - If you have a custom requirement or would like to stitch the native ad assets yourself, Polymorph SDK supports this by requesting a single native ad\n\n**Integrating Other Networks**\nIf you wish to add other networks for mediation, [**click here**](https://dev.getpolymorph.com/docs/android-sdk#integrating-other-networks) to know how to do this.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Content Stream Ads\"\n}\n[/block]\nTo display ads in content stream, you just need to implement following 3 simple steps.\n1. Define ad layout(s)\n2. Define ad positions\n3. Create Polymorph custom adapter object and start loading ads\n\nDepending on which type of stream you want to load native ads into, see one of the below sections\n  * [**Recycler View Integration**](https://dev.getpolymorph.com/docs/android-sdk#recycler-view-integration)\n  * [**List or Grid View Integration**](https://dev.getpolymorph.com/docs/android-sdk#list-or-grid-view-integration)\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Recycler View Integration\"\n}\n[/block]\nIf your Android application uses RecyclerView to show the content, you can use our SDK's RecyclerView wrapper class *ANRecyclerView* to load native ads.\n\n1. Create an instance of *ANRecyclerAdapter* class before onCreate() method so you can use the object to load ads later.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"private ANRecyclerAdapter anRecyclerAdapter;\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n2. Define Ad Layout\nCheck [**this section**](https://dev.getpolymorph.com/docs/android-sdk#native-ad-layout) for defining native ad layouts and dynamic layout switching.\n\n3. Define Ad Positions\nCheck [**this section**](https://dev.getpolymorph.com/docs/android-sdk#ad-positions) for defining server ad positions and client ad positions.\n\n4. Create *ANRecyclerAdapter* object and begin loading ads\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \":::at:::Override\\npublic View onCreate(...) {\\n    // ...\\n    // ...\\n    // create ANRecyclerAdapter object\\n    anRecyclerAdapter = new ANRecyclerAdapter(this, adapter,\\n                                      AD_UNIT_ID, serverPositions);\\n    // Register the renderer with the ANRecyclerAdapter\\n    anRecyclerAdapter.registerViewBinder(anAdViewBinder);\\n    // Set your original view's adapter to ANRecyclerAdapter instance\\n    listView.setAdapter(anRecyclerAdapter);\\n    // Start loading ads\\n    anRecyclerAdapter.loadAds();\\n}\\n\\n@Override\\npublic void onResume() {\\n    // We recommend loading new ads when the user returns to your activity\\n    anRecyclerAdapter.loadAds();\\n}\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"List or Grid View Integration\"\n}\n[/block]\nIf your Android application uses ListView or GridView or any view that uses Adapter, we recommend you to use our SDK's adapter class *ANListAdapter* to load native ads.\n\n1. Create an instance of *ANListAdapter* class before onCreate() method so you can use the object to load ads later.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"private ANListAdapter anListAdapter;\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n2. Define Ad Layout\nCheck [**this section**](https://dev.getpolymorph.com/docs/android-sdk#native-ad-layout) for defining native ad layouts and dynamic layout switching.\n\n3. Define Ad Positions\nCheck [**this section**](https://dev.getpolymorph.com/docs/android-sdk#ad-positions) for defining server ad positions and client ad positions.\n\n4. Create *ANListAdapter* object and begin loading ads\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"\\n@Override\\npublic View onCreate(...) {\\n    // ...\\n    // ...\\n    // create ANListAdapter object\\n    anListAdapter = new ANListAdapter(this, adapter,\\n                                      AD_UNIT_ID, serverPositions);\\n    // Register the renderer with the ANListAdapter\\n    anListAdapter.registerViewBinder(anAdViewBinder);\\n    // Set your original view's adapter to ANListAdapter instance\\n    listView.setAdapter(anListAdapter);\\n    // Start loading ads\\n    anListAdapter.loadAds();\\n}\\n\\n@Override\\npublic void onResume() {\\n    // We recommend loading new ads when the user returns to your activity\\n    anListAdapter.loadAds();\\n}\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Standard Integration\"\n}\n[/block]\nIf you are looking to load ads manually instead of using our RecyclerView or ListView wrappers, or if your Android application is not built using RecyclerView or ListView, then you can follow the integration steps below to manually load and render ads.\n\n1. Create an instance of *ANNativeAd* class before onCreate() method so you can use the object to load ads later.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"private ANNativeAd mNativeAd;\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n2. Initialize the instance and set listener for ad callbacks inside your *onCreate()* method\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"mNativeAd = new ANNativeAd(this, <AD_UNIT_ID>);\\nmNativeAd.setNativeAdListener(new ANAdListener() {\\n    @Override\\n    public void onAdLoaded(NativeAdUnit nativeAdUnit) {\\n    }\\n  \\n    @Override\\n    public void onAdFailed(String message) {\\n    }\\n\\n    @Override\\n    public void onAdImpressionRecorded() {\\n    }\\n  \\n    @Override\\n    public void onAdClicked() {\\n    }\\n});\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n3. Start loading ads in your *onStart()* and *onResume()* methods by adding the following line of code.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"@Override\\npublic void onResume() {\\n    mNativeAd.loadAd();\\n    // ...\\n}\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n4. The next step is to extract the ad assets and build your custom UI for displaying native ads. Override the *onAdLoaded()* method as set in your ad listener above to retrieve the ad assets.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"@Override\\npublic void onAdLoaded(NativeAdUnit nativeAdUnit) {\\n    String title = nativeAdUnit.getTitle();\\n    String summary = nativeAdUnit.getSummary();\\n    String iconImage = nativeAdUnit.getIconImage();\\n    String mainImage = nativeAdUnit.getMainImage();\\n    String cta = nativeAdUnit.getCallToAction();\\n\\n    // Define your custom layout and start loading assets into it\\n    // ...\\n}\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n5. Polymorph SDK internally handles impression and click tracking. You only need to register your ad view with the SDK as below.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"mNativeAd.attachViewForInteraction(nativeAdUnit, <NATIVE_AD_VIEW>);\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\nAlternatively, you can let the SDK handle loading assets into the layout defined by you and create an ad view. We recommend this approach as it's much cleaner and it only requires for you to define the layout XML.\n\nCheck [**this section**](https://dev.getpolymorph.com/docs/android-sdk#native-ad-layout) for defining ad layout.\n\nOnce you have defined the layout and registered the view binder, you can override *onAdLoaded()* method and add the following line to create ad view with the assets into the layout defined by you.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"@Override\\npublic void onAdLoaded(NativeAdUnit nativeAdUnit) {\\n    View nativeAdView = mNativeAd.renderAdView(nativeAdUnit);\\n    // the above method only creates the ad view, you need to add the view to your container as desired\\n    <your_container_object>.addView(nativeAdView);\\n}\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\nSince SDK is handling the creation of ad view, it implicitly takes care of tracking impressions and clicks.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Native Ad Layout\"\n}\n[/block]\nYou can define any custom layout for how your native ad should look within your app content. SDK will use this layout to load ads into it.\n\nStart by defining XML layout, the default assets available are title, summary, icon image, main image and call to action. Place the XML under **res/layout/<native_ad_layout>.xml** of your Android project.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"final ANAdViewBinder anAdViewBinder = new\\n  ANAdViewBinder.Builder(R.layout.<NATIVE_AD_LAYOUT_XML>)\\n  \\t.bindTitle(R.id.<title>)\\n\\t\\t.bindSummary(R.id.<summary>)\\n\\t\\t.bindIconImage(R.id.<iconImage>)\\n\\t\\t.bindMainImage(R.id.<mainImage>)\\n\\t\\t.bindCallToAction(R.id.<callToAction>)\\n\\t\\t.bindPromotedBy(R.id.<promotedBy>)\\n\\t\\t.build();\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\nOnce layout xml is defined, you need to register the same through with SDK, through *ANViewBinder*, which will take care of rendering the ads into the layout.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"// For RecyclerView integration\\nanRecyclerAdapter.registerViewBinder(anAdViewBinder);\\n\\n// For List or Grid View integration\\nanListAdapter.registerViewBinder(anAdViewBinder);\\n\\n// For standard (single native ad) integration\\nmNativeAd.registerViewBinder(anAdViewBinder);\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n**Dynamic Layout Switching**\n\nPolymorph SDK has the ability to dynamically switch between multiple ad layouts through just a click on the UI.\n\nDynamic layouts is enabled by default for every ad placement. Following steps are required during the integration to make use of dynamic layouts.\n\n1. Define all layout XMLs that you want to dynamically switch between. For example, if you have 4 layouts you would like to dynamically switch between then you need to create 4 XMLs and place them under **/res/layout/** of your Android project.\n\n2. Define layouts with default R.ids for assets for ease of integration. Please check the snippet below.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<TextView android:id=\\\"@+id/an_title\\\"\\n          .../>\\n<TextView android:id=\\\"@+id/an_summary\\\"\\n          .../>\\n<ImageView android:id=\\\"@+id/an_icon_image\\\"\\n          .../>\\n<ImageView android:id=\\\"@+id/an_main_image\\\"\\n          .../>\\n<Button android:id=\\\"@+id/an_call_to_action\\\"\\n          .../>\\n<TextView android:id=\\\"@+id/an_promoted_by\\\"\\n          .../>\\n<!--\\nan_title -> for title\\nan_summary -> for summary or description\\nan_icon_image -> icon image that appears usually top left\\nan_main_image -> large image that appears usually in the center\\nan_call_to_action -> cta or call-to-action button\\nan_promoted_by -> this is a sponsored by tag (mandatory)\\n-->\",\n      \"language\": \"xml\"\n    }\n  ]\n}\n[/block]\n3. Register view binder using *bindAssetsWithDefaultKeys()* method. This method automatically binds assets using the default R.ids specified in the layout above.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"final ANAdViewBinder anAdViewBinder = new\\n  ANAdViewBinder.Builder(R.layout.<NATIVE_AD_LAYOUT_XML>)\\n  \\t.bindAssetsWithDefaultKeys(this)\\n\\t\\t.build();\\nmNativeAd.registerViewBinder(anAdViewBinder);\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\nNOTE: If you wish to use custom R.ids, you may do so. In which case you will not be able to use *bindAssetsWithDefaultKeys()*, you will have to use respective bind methods as shown in the beginning of the section. However, for dynamic layouts to work, you need to use same custom R.ids across all your XML layouts and also ensure you are binding all assets irrespective of which and how many assets are used in the currently active layout.\n\n**Backup Layouts**\n\nPolymorph SDK may sometimes serve ads without icon image. If you are using icon in one of your layouts, it will be blank in such cases. To counter this, SDK has a feature built-in to fallback automatically into a backup layout (if defined).\nTo make use of backup layouts, you need to define the xml with the same name as your original layout with _backup suffix added to it. For example, if your original layout file is named as **native_ad_layout.xml** then your backup layout should be named as **native_ad_layout_backup.xml**\n\n**Custom Assets**\n\nIf you have direct-sold native ads, Polymorph allows you to set up additional custom assets (text and/or images) which you can extract or render using the SDK.\nOnce you had setup additional assets in the UI, add them to your layout XML file(s) and bind them as shown below.\n(Example shown below assumes **customText** and **customImage** keys added in UI and **R.id.custom_text** and **R.id.custom_image** added to layout XML)\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"final ANAdViewBinder anAdViewBinder = new\\n  ANAdViewBinder.Builder(R.layout.<NATIVE_AD_LAYOUT_XML>)\\n  \\t.bindAssetsWithDefaultKeys(this)\\n    .bindCustomField(\\\"customText\\\", R.id.custom_text\\n    .bindCustomField(\\\"customImage\\\", R.id.custom_image\\n\\t\\t.build();\\nmNativeAd.registerViewBinder(anAdViewBinder);\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\nSDK internally takes care of rendering the custom assets as per the layout specified. But if if you are using standard integration and want to extract custom assets to bind and render on your own, then you can do so as shown below.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"@Override\\npublic void onAdLoaded(NativeAdUnit nativeAdUnit) {\\n    Object customText = nativeAdUnit.getCustomField(\\\"customText\\\");\\n    // for images, the source url is returned\\n    Object customImage = nativeAdUnit.getCustomField(\\\"customImage\\\");\\n    \\n    // you can also extract all custom assets at once into a map and extract using the keys as specified in the UI\\n    Map<String, Object> customFields = nativeAdUnit.getCustomFields();\\n}\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n**Video Ads**\n\nPolymorph SDK supports showing video assets in-line with autoplay. To enable this you need to use **View** class to define the asset in your layout, instead of ImageView. Inline Video is usually shown in place of main image.\n\nSample layout XML definition for video\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<View android:id=\\\"@+id/an_video\\\"\\n    android:layout_width=\\\"match_parent\\\"\\n    android:layout_height=\\\"200dp\\\"\\n    android:background=\\\"@null\\\"\\n    android:layout_marginTop=\\\"10dp\\\"\\n    android:layout_marginLeft=\\\"10dp\\\"\\n    android:layout_marginRight=\\\"10dp\\\"\\n    android:layout_below=\\\"@+id/an_summary\\\"\\n    android:layout_alignParentLeft=\\\"true\\\"\\n    android:contentDescription=\\\"Native Inline Video\\\"\\n    android:scaleType=\\\"fitXY\\\"/>\",\n      \"language\": \"xml\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Ad Positions\"\n}\n[/block]\nAd positions define where the ads should be loaded into your ListView. You can define ad positions on the server side or on the client side in your app.\n\n**Dynamic Ad Positions (Server Positions) - Recommended**\n\nYou can define ad positions on Polymorph UI at each placement level and you can change them anytime without republishing the app. The ad positions are dynamically updated as you make the changes on the UI.\nUse the following line of code to define server positions in your app before publishing. By passing the instance of *ServerPositions*, SDK knows that it has to fetch ad positions from server and will do so automatically.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"ANAdPositions.ServerPositions serverPositions =\\n  \\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\tANAdPositions.serverPositioning();\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n**Hardcode Ad Positions in the App (Client Positions)**\n\nIf you don't wish to use server positions and want to use static positions, then you can define them through *ClientPositions* as below.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"ANAdPositions.ClientPositions clientPositions =\\n  \\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\tANAdPositions.clientPositioning();\\n// add fixed positions\\nclientPositions.addFixedPosition(5).addFixedPosition(10);\\n// add repeating position interval\\nclientPositions.enableRepeatingPositions(8);\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Integrating Other Networks\"\n}\n[/block]\nThis section details how to integrate other networks for mediation.\n\n**Basic Integration Guidelines**\n\nCurrently, we have built adapters for 4 major ad networks. Depending on which network you wish to integrate, choose the corresponding subsection. However, before diving into one specific network, you have to follow these basic steps for any network you wish to integrate.\n\n1. Integrate network SDK into your project\n2. From the \"networks\" folder of the downloaded Polymorph SDK, copy the corresponding network adapter into your project\n3. Setup network specific data on Polymorph dashboard.\n\n**Facebook**\n\n1. The easiest way to integrate Audience Network SDK from Facebook is by adding following line to your gradle dependencies.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"dependencies {\\n    compile 'com.facebook.android:audience-network-sdk:4.x.x'\\n}\",\n      \"language\": \"groovy\"\n    }\n  ]\n}\n[/block]\nNOTE: Audience Network SDK version supported is 4.6.0 & above.\n\n2. Copy networks/FacebookAdNetwork.java from Polymorph SDK into your project. You can copy into any java package under **src/** (example **com.xyz.networks.FacebookAdNetwork**)\n\nOn Polymorph dashboard,\n1. Click on the [**Programmatic**](https://console.getpolymorph.com/demand/#/) tab\n2. Click on the [**Bidders & Networks**](https://console.getpolymorph.com/demand/#/network) tab\n3. Click the [**+Network**](https://console.getpolymorph.com/demand/#/network/create/) button\n\nSelect \"Facebook\" from the \"mobile_sdk\" section and enter your facebook credentials. Credentials are used to fetch placement information and reports data for revenue optimization only.\n\n\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/4c7f4e4-Screen_Shot_2018-01-29_at_12.18.30_AM.png\",\n        \"Screen Shot 2018-01-29 at 12.18.30 AM.png\",\n        1048,\n        614,\n        \"#3a4b5d\"\n      ]\n    }\n  ]\n}\n[/block]\nOnce created, you will be taken to the network campaign screen where you need to fill in THREE fields\n* **Adapter Class Name** (The class name of the Polymorph SDK adapter in your app integration)\n* **Placement ID** key's value is your placement that Facebook gives after you register your app with them.\n* **App Token** can be found on facebook dashboard\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/dd7e465-Screen_Shot_2018-01-29_at_12.25.24_AM.png\",\n        \"Screen Shot 2018-01-29 at 12.25.24 AM.png\",\n        1372,\n        980,\n        \"#eeeff0\"\n      ]\n    }\n  ]\n}\n[/block]\n\n**MoPub**\n\n1. The easiest way to integrate MoPub SDK is by adding following lines to your gradle dependencies.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"dependencies {\\n    compile('com.mopub:mopub-sdk-base:4.11.0@aar')\\n    compile('com.mopub:mopub-sdk-native-static:4.11.0@aar')\\n    compile('com.mopub.volley:mopub-volley:1.1.0@aar')\\n}\",\n      \"language\": \"groovy\"\n    }\n  ]\n}\n[/block]\nNOTE: MoPub SDK version supported is 4.0.0 & above.\n\n2. Copy networks/MoPubAdNetwork.java from Polymorph SDK into your project. You must copy into **com.mopub.nativeads** package under **src/**\n\nFollow the same steps for setting up the network campaign on Polymorph dashboard as shown for Facebook\n\nNOTE: MoPub ads may not work if you copy mopub adapter class into a different package other than **com.mopub.nativeads**\n\n\n**InMobi**\n\n1. Download InMobi SDK from InMobi portal and copy InMobi-5.x.x.jar to your project's lib folder. Add add the following line to your gradle dependencies.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"\\nrepositories {\\n    flatDir {\\n        dirs 'libs'\\n    }\\n}\\n// ...\\ndependencies {\\n    compile(name:'InMobi-5.x.x', ext:'jar')\\n}\",\n      \"language\": \"groovy\"\n    }\n  ]\n}\n[/block]\nNOTE: InMobi SDK version supported is 5.0.0 & above.\n\n2. Copy networks/InMobiAdNetwork.java from Polymorph SDK into your project. You can copy into any java package under **src/** (example **com.xyz.networks.InMobiAdNetwork**)\n\nFollow the same steps for setting up the network campaign on Polymorph dashboard as shown on Facebook\n\n\n**Flurry**\n\n1. Download InMobi SDK from InMobi portal and copy InMobi-5.x.x.jar to your project's lib folder. Add add the following lines to your gradle dependencies.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"repositories {\\n    flatDir {\\n        dirs 'libs'\\n    }\\n}\\n// ...\\ndependencies {\\n    compile(name:'FlurryAds-6.x.x', ext:'jar')\\n    compile(name:'FlurryAnalytics-6.x.x', ext:'jar')\\n}\",\n      \"language\": \"groovy\"\n    }\n  ]\n}\n[/block]\nNOTE: Flurry SDK version supported is 6.1.0 & above.\n\n2. Copy networks/FlurryAdNetwork.java from Polymorph SDK into your project. You can copy into any java package under **src/** (example **com.xyz.networks.FlurryAdNetwork**)\n\nFollow the same steps for setting up the network campaign on Polymorph dashboard as shown for Facebook\n\n\n**DFP**\n\n1. The easiest way to integrate DFP SDK is by adding following lines to your gradle dependencies.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"dependencies {\\n    compile 'com.google.android.gms:play-services-ads:11.4.0'\\n    compile 'com.google.android.gms:play-services-location:11.4.0'\\n}\",\n      \"language\": \"groovy\"\n    }\n  ]\n}\n[/block]\n2. Copy networks/DFPAdNetwork.java from Polymorph SDK into your project. You can copy into any java package under **src/** (example **com.xyz.networks.DFPAdNetwork**)\n\nCheck this page on how to setup/enable API access for your DFP account (needing for pulling reports):\nhttps://developers.google.com/doubleclick-publishers/docs/start\n\nWhile adding the network, please note below:\n* **username**  - application name in dfp\n* **password**  - dfp network id\n* **access token**  - content of json file downloaded in `Create authentication credentials` section here: https://developers.google.com/doubleclick-publishers/docs/start\n\nAfter adding the network, you could follow the same steps for setting up the network campaign on Polymorph dashboard as shown on Facebook. \n\nPlease note that DFP custom template id is mandatory along with DFP placement id. We currently do not support the default DFP templates (app-install and content-ad), so we require you to create a custom template for the assets you want on the DFP dashboard, under Creatives -> Native Ad Formats. Please ensure you are using the following labels while defining a custom template, else you may not get the desired asset.\n\nHeadline - this is the label our adapter uses for Title\nBody - this is the label our adapter uses for Summary\nIconImage - this is the label for icon image\nMainImage - this is the label for main image\nCallToAction - this is the label for call-to-action (CTA)","excerpt":"","slug":"android-sdk","type":"basic","title":"Android SDK"}
Welcome to Polymorph Android SDK documentation. Please check out the "Getting Started" section below before integrating your app with the SDK. [block:api-header] { "type": "basic", "title": "Getting Started" } [/block] This section explains the process of including Polymorph SDK in your Android application and setting dependencies. ** Prerequisites and Dependencies ** * Android version 4.0.3 (API 15) and above Add following to your build.gradle [block:code] { "codes": [ { "code": "dependencies {\n compile 'com.android.support:support-v4:22.2.1'\n compile 'com.android.support:appcompat-v7:22.2.1'\n compile 'com.android.support:recyclerview-v7:22.2.1'\n compile 'com.google.android.gms:play-services:7.8.0'\n}", "language": "groovy" } ] } [/block] **Including Polymorph SDK in your Android project** Click [**here**](https://github.com/picatcha/adsnative-sdk-android/archive/master.zip) to download the SDK as zipped source. Extract **adsnative_sdk_2.0.0.aar** from <unzipped>/adsnative_sdk/ location and place it under your project's libs folder (create libs if not already done). Add the compiled .aar to your build.gradle file as below. [block:code] { "codes": [ { "code": "repositories {\n flatDir {\n dirs 'libs'\n }\n}\n// ...\ndependencies {\n compile(name:'adsnative_sdk_2.0.0', ext:'aar')\n}", "language": "groovy" } ] } [/block] **Required Permissions in Android Manifest** Following permissions are mandatory. Please add them to your AndroidManifest.xml 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] **Recommended Permissions in Android Manifest** We recommend adding following permissions to your AndroidManifest.xml. [block:code] { "codes": [ { "code": "<uses-permission android:name=\"android.permission.ACCESS_COARSE_LOCATION\" />\n<uses-permission android:name=\"android.permission.ACCESS_FINE_LOCATION\" />", "language": "xml" } ] } [/block] **ProGuard** Polymorph SDK is already obfuscated and minified using ProGuard. If you are running ProGuard on your Android application, please add the following to your ProGuard configuration file. [block:code] { "codes": [ { "code": "-keep class com.adsnative.** { *; }\n-dontwarn com.adsnative.**", "language": "groovy" } ] } [/block] [block:api-header] { "type": "basic", "title": "Native Ads Integration" } [/block] Import Polymorph SDK classes into your activity by adding the following line of code to the imports section of your activity class. [block:code] { "codes": [ { "code": "import com.adsnative.ads.*;", "language": "java" } ] } [/block] Polymorph SDK supports following ad formats. Depending on your requirement and the type of app you have, you can choose one of the below methods. * [**Content Stream Ads**](https://dev.getpolymorph.com/docs/android-sdk#content-stream-ads) - These are ads that appear as part of a content stream. For Android, we support the RecyclerView and TableView/GridView layouts. If your app is using an adapter to show content stream then we highly recommend using this integration. * [**Standard Integration (Single Native Ad)**](https://dev.getpolymorph.com/docs/android-sdk#standard-integration) - If you have a custom requirement or would like to stitch the native ad assets yourself, Polymorph SDK supports this by requesting a single native ad **Integrating Other Networks** If you wish to add other networks for mediation, [**click here**](https://dev.getpolymorph.com/docs/android-sdk#integrating-other-networks) to know how to do this. [block:api-header] { "type": "basic", "title": "Content Stream Ads" } [/block] To display ads in content stream, you just need to implement following 3 simple steps. 1. Define ad layout(s) 2. Define ad positions 3. Create Polymorph custom adapter object and start loading ads Depending on which type of stream you want to load native ads into, see one of the below sections * [**Recycler View Integration**](https://dev.getpolymorph.com/docs/android-sdk#recycler-view-integration) * [**List or Grid View Integration**](https://dev.getpolymorph.com/docs/android-sdk#list-or-grid-view-integration) [block:api-header] { "type": "basic", "title": "Recycler View Integration" } [/block] If your Android application uses RecyclerView to show the content, you can use our SDK's RecyclerView wrapper class *ANRecyclerView* to load native ads. 1. Create an instance of *ANRecyclerAdapter* class before onCreate() method so you can use the object to load ads later. [block:code] { "codes": [ { "code": "private ANRecyclerAdapter anRecyclerAdapter;", "language": "java" } ] } [/block] 2. Define Ad Layout Check [**this section**](https://dev.getpolymorph.com/docs/android-sdk#native-ad-layout) for defining native ad layouts and dynamic layout switching. 3. Define Ad Positions Check [**this section**](https://dev.getpolymorph.com/docs/android-sdk#ad-positions) for defining server ad positions and client ad positions. 4. Create *ANRecyclerAdapter* object and begin loading ads [block:code] { "codes": [ { "code": "@Override\npublic View onCreate(...) {\n // ...\n // ...\n // create ANRecyclerAdapter object\n anRecyclerAdapter = new ANRecyclerAdapter(this, adapter,\n AD_UNIT_ID, serverPositions);\n // Register the renderer with the ANRecyclerAdapter\n anRecyclerAdapter.registerViewBinder(anAdViewBinder);\n // Set your original view's adapter to ANRecyclerAdapter instance\n listView.setAdapter(anRecyclerAdapter);\n // Start loading ads\n anRecyclerAdapter.loadAds();\n}\n\n@Override\npublic void onResume() {\n // We recommend loading new ads when the user returns to your activity\n anRecyclerAdapter.loadAds();\n}", "language": "java" } ] } [/block] [block:api-header] { "type": "basic", "title": "List or Grid View Integration" } [/block] If your Android application uses ListView or GridView or any view that uses Adapter, we recommend you to use our SDK's adapter class *ANListAdapter* to load native ads. 1. Create an instance of *ANListAdapter* class before onCreate() method so you can use the object to load ads later. [block:code] { "codes": [ { "code": "private ANListAdapter anListAdapter;", "language": "java" } ] } [/block] 2. Define Ad Layout Check [**this section**](https://dev.getpolymorph.com/docs/android-sdk#native-ad-layout) for defining native ad layouts and dynamic layout switching. 3. Define Ad Positions Check [**this section**](https://dev.getpolymorph.com/docs/android-sdk#ad-positions) for defining server ad positions and client ad positions. 4. Create *ANListAdapter* object and begin loading ads [block:code] { "codes": [ { "code": "\n@Override\npublic View onCreate(...) {\n // ...\n // ...\n // create ANListAdapter object\n anListAdapter = new ANListAdapter(this, adapter,\n AD_UNIT_ID, serverPositions);\n // Register the renderer with the ANListAdapter\n anListAdapter.registerViewBinder(anAdViewBinder);\n // Set your original view's adapter to ANListAdapter instance\n listView.setAdapter(anListAdapter);\n // Start loading ads\n anListAdapter.loadAds();\n}\n\n@Override\npublic void onResume() {\n // We recommend loading new ads when the user returns to your activity\n anListAdapter.loadAds();\n}", "language": "java" } ] } [/block] [block:api-header] { "type": "basic", "title": "Standard Integration" } [/block] If you are looking to load ads manually instead of using our RecyclerView or ListView wrappers, or if your Android application is not built using RecyclerView or ListView, then you can follow the integration steps below to manually load and render ads. 1. Create an instance of *ANNativeAd* class before onCreate() method so you can use the object to load ads later. [block:code] { "codes": [ { "code": "private ANNativeAd mNativeAd;", "language": "java" } ] } [/block] 2. Initialize the instance and set listener for ad callbacks inside your *onCreate()* method [block:code] { "codes": [ { "code": "mNativeAd = new ANNativeAd(this, <AD_UNIT_ID>);\nmNativeAd.setNativeAdListener(new ANAdListener() {\n @Override\n public void onAdLoaded(NativeAdUnit nativeAdUnit) {\n }\n \n @Override\n public void onAdFailed(String message) {\n }\n\n @Override\n public void onAdImpressionRecorded() {\n }\n \n @Override\n public void onAdClicked() {\n }\n});", "language": "java" } ] } [/block] 3. Start loading ads in your *onStart()* and *onResume()* methods by adding the following line of code. [block:code] { "codes": [ { "code": "@Override\npublic void onResume() {\n mNativeAd.loadAd();\n // ...\n}", "language": "java" } ] } [/block] 4. The next step is to extract the ad assets and build your custom UI for displaying native ads. Override the *onAdLoaded()* method as set in your ad listener above to retrieve the ad assets. [block:code] { "codes": [ { "code": "@Override\npublic void onAdLoaded(NativeAdUnit nativeAdUnit) {\n String title = nativeAdUnit.getTitle();\n String summary = nativeAdUnit.getSummary();\n String iconImage = nativeAdUnit.getIconImage();\n String mainImage = nativeAdUnit.getMainImage();\n String cta = nativeAdUnit.getCallToAction();\n\n // Define your custom layout and start loading assets into it\n // ...\n}", "language": "java" } ] } [/block] 5. Polymorph SDK internally handles impression and click tracking. You only need to register your ad view with the SDK as below. [block:code] { "codes": [ { "code": "mNativeAd.attachViewForInteraction(nativeAdUnit, <NATIVE_AD_VIEW>);", "language": "java" } ] } [/block] Alternatively, you can let the SDK handle loading assets into the layout defined by you and create an ad view. We recommend this approach as it's much cleaner and it only requires for you to define the layout XML. Check [**this section**](https://dev.getpolymorph.com/docs/android-sdk#native-ad-layout) for defining ad layout. Once you have defined the layout and registered the view binder, you can override *onAdLoaded()* method and add the following line to create ad view with the assets into the layout defined by you. [block:code] { "codes": [ { "code": "@Override\npublic void onAdLoaded(NativeAdUnit nativeAdUnit) {\n View nativeAdView = mNativeAd.renderAdView(nativeAdUnit);\n // the above method only creates the ad view, you need to add the view to your container as desired\n <your_container_object>.addView(nativeAdView);\n}", "language": "java" } ] } [/block] Since SDK is handling the creation of ad view, it implicitly takes care of tracking impressions and clicks. [block:api-header] { "type": "basic", "title": "Native Ad Layout" } [/block] You can define any custom layout for how your native ad should look within your app content. SDK will use this layout to load ads into it. Start by defining XML layout, the default assets available are title, summary, icon image, main image and call to action. Place the XML under **res/layout/<native_ad_layout>.xml** of your Android project. [block:code] { "codes": [ { "code": "final ANAdViewBinder anAdViewBinder = new\n ANAdViewBinder.Builder(R.layout.<NATIVE_AD_LAYOUT_XML>)\n \t.bindTitle(R.id.<title>)\n\t\t.bindSummary(R.id.<summary>)\n\t\t.bindIconImage(R.id.<iconImage>)\n\t\t.bindMainImage(R.id.<mainImage>)\n\t\t.bindCallToAction(R.id.<callToAction>)\n\t\t.bindPromotedBy(R.id.<promotedBy>)\n\t\t.build();", "language": "java" } ] } [/block] Once layout xml is defined, you need to register the same through with SDK, through *ANViewBinder*, which will take care of rendering the ads into the layout. [block:code] { "codes": [ { "code": "// For RecyclerView integration\nanRecyclerAdapter.registerViewBinder(anAdViewBinder);\n\n// For List or Grid View integration\nanListAdapter.registerViewBinder(anAdViewBinder);\n\n// For standard (single native ad) integration\nmNativeAd.registerViewBinder(anAdViewBinder);", "language": "java" } ] } [/block] **Dynamic Layout Switching** Polymorph SDK has the ability to dynamically switch between multiple ad layouts through just a click on the UI. Dynamic layouts is enabled by default for every ad placement. Following steps are required during the integration to make use of dynamic layouts. 1. Define all layout XMLs that you want to dynamically switch between. For example, if you have 4 layouts you would like to dynamically switch between then you need to create 4 XMLs and place them under **/res/layout/** of your Android project. 2. Define layouts with default R.ids for assets for ease of integration. Please check the snippet below. [block:code] { "codes": [ { "code": "<TextView android:id=\"@+id/an_title\"\n .../>\n<TextView android:id=\"@+id/an_summary\"\n .../>\n<ImageView android:id=\"@+id/an_icon_image\"\n .../>\n<ImageView android:id=\"@+id/an_main_image\"\n .../>\n<Button android:id=\"@+id/an_call_to_action\"\n .../>\n<TextView android:id=\"@+id/an_promoted_by\"\n .../>\n<!--\nan_title -> for title\nan_summary -> for summary or description\nan_icon_image -> icon image that appears usually top left\nan_main_image -> large image that appears usually in the center\nan_call_to_action -> cta or call-to-action button\nan_promoted_by -> this is a sponsored by tag (mandatory)\n-->", "language": "xml" } ] } [/block] 3. Register view binder using *bindAssetsWithDefaultKeys()* method. This method automatically binds assets using the default R.ids specified in the layout above. [block:code] { "codes": [ { "code": "final ANAdViewBinder anAdViewBinder = new\n ANAdViewBinder.Builder(R.layout.<NATIVE_AD_LAYOUT_XML>)\n \t.bindAssetsWithDefaultKeys(this)\n\t\t.build();\nmNativeAd.registerViewBinder(anAdViewBinder);", "language": "java" } ] } [/block] NOTE: If you wish to use custom R.ids, you may do so. In which case you will not be able to use *bindAssetsWithDefaultKeys()*, you will have to use respective bind methods as shown in the beginning of the section. However, for dynamic layouts to work, you need to use same custom R.ids across all your XML layouts and also ensure you are binding all assets irrespective of which and how many assets are used in the currently active layout. **Backup Layouts** Polymorph SDK may sometimes serve ads without icon image. If you are using icon in one of your layouts, it will be blank in such cases. To counter this, SDK has a feature built-in to fallback automatically into a backup layout (if defined). To make use of backup layouts, you need to define the xml with the same name as your original layout with _backup suffix added to it. For example, if your original layout file is named as **native_ad_layout.xml** then your backup layout should be named as **native_ad_layout_backup.xml** **Custom Assets** If you have direct-sold native ads, Polymorph allows you to set up additional custom assets (text and/or images) which you can extract or render using the SDK. Once you had setup additional assets in the UI, add them to your layout XML file(s) and bind them as shown below. (Example shown below assumes **customText** and **customImage** keys added in UI and **R.id.custom_text** and **R.id.custom_image** added to layout XML) [block:code] { "codes": [ { "code": "final ANAdViewBinder anAdViewBinder = new\n ANAdViewBinder.Builder(R.layout.<NATIVE_AD_LAYOUT_XML>)\n \t.bindAssetsWithDefaultKeys(this)\n .bindCustomField(\"customText\", R.id.custom_text\n .bindCustomField(\"customImage\", R.id.custom_image\n\t\t.build();\nmNativeAd.registerViewBinder(anAdViewBinder);", "language": "java" } ] } [/block] SDK internally takes care of rendering the custom assets as per the layout specified. But if if you are using standard integration and want to extract custom assets to bind and render on your own, then you can do so as shown below. [block:code] { "codes": [ { "code": "@Override\npublic void onAdLoaded(NativeAdUnit nativeAdUnit) {\n Object customText = nativeAdUnit.getCustomField(\"customText\");\n // for images, the source url is returned\n Object customImage = nativeAdUnit.getCustomField(\"customImage\");\n \n // you can also extract all custom assets at once into a map and extract using the keys as specified in the UI\n Map<String, Object> customFields = nativeAdUnit.getCustomFields();\n}", "language": "java" } ] } [/block] **Video Ads** Polymorph SDK supports showing video assets in-line with autoplay. To enable this you need to use **View** class to define the asset in your layout, instead of ImageView. Inline Video is usually shown in place of main image. Sample layout XML definition for video [block:code] { "codes": [ { "code": "<View android:id=\"@+id/an_video\"\n android:layout_width=\"match_parent\"\n android:layout_height=\"200dp\"\n android:background=\"@null\"\n android:layout_marginTop=\"10dp\"\n android:layout_marginLeft=\"10dp\"\n android:layout_marginRight=\"10dp\"\n android:layout_below=\"@+id/an_summary\"\n android:layout_alignParentLeft=\"true\"\n android:contentDescription=\"Native Inline Video\"\n android:scaleType=\"fitXY\"/>", "language": "xml" } ] } [/block] [block:api-header] { "type": "basic", "title": "Ad Positions" } [/block] Ad positions define where the ads should be loaded into your ListView. You can define ad positions on the server side or on the client side in your app. **Dynamic Ad Positions (Server Positions) - Recommended** You can define ad positions on Polymorph UI at each placement level and you can change them anytime without republishing the app. The ad positions are dynamically updated as you make the changes on the UI. Use the following line of code to define server positions in your app before publishing. By passing the instance of *ServerPositions*, SDK knows that it has to fetch ad positions from server and will do so automatically. [block:code] { "codes": [ { "code": "ANAdPositions.ServerPositions serverPositions =\n \t\t\t\t\t\t\t\t\t\t\t\t\t\tANAdPositions.serverPositioning();", "language": "java" } ] } [/block] **Hardcode Ad Positions in the App (Client Positions)** If you don't wish to use server positions and want to use static positions, then you can define them through *ClientPositions* as below. [block:code] { "codes": [ { "code": "ANAdPositions.ClientPositions clientPositions =\n \t\t\t\t\t\t\t\t\t\t\t\t\t\tANAdPositions.clientPositioning();\n// add fixed positions\nclientPositions.addFixedPosition(5).addFixedPosition(10);\n// add repeating position interval\nclientPositions.enableRepeatingPositions(8);", "language": "java" } ] } [/block] [block:api-header] { "type": "basic", "title": "Integrating Other Networks" } [/block] This section details how to integrate other networks for mediation. **Basic Integration Guidelines** Currently, we have built adapters for 4 major ad networks. Depending on which network you wish to integrate, choose the corresponding subsection. However, before diving into one specific network, you have to follow these basic steps for any network you wish to integrate. 1. Integrate network SDK into your project 2. From the "networks" folder of the downloaded Polymorph SDK, copy the corresponding network adapter into your project 3. Setup network specific data on Polymorph dashboard. **Facebook** 1. The easiest way to integrate Audience Network SDK from Facebook is by adding following line to your gradle dependencies. [block:code] { "codes": [ { "code": "dependencies {\n compile 'com.facebook.android:audience-network-sdk:4.x.x'\n}", "language": "groovy" } ] } [/block] NOTE: Audience Network SDK version supported is 4.6.0 & above. 2. Copy networks/FacebookAdNetwork.java from Polymorph SDK into your project. You can copy into any java package under **src/** (example **com.xyz.networks.FacebookAdNetwork**) On Polymorph dashboard, 1. Click on the [**Programmatic**](https://console.getpolymorph.com/demand/#/) tab 2. Click on the [**Bidders & Networks**](https://console.getpolymorph.com/demand/#/network) tab 3. Click the [**+Network**](https://console.getpolymorph.com/demand/#/network/create/) button Select "Facebook" from the "mobile_sdk" section and enter your facebook credentials. Credentials are used to fetch placement information and reports data for revenue optimization only. [block:image] { "images": [ { "image": [ "https://files.readme.io/4c7f4e4-Screen_Shot_2018-01-29_at_12.18.30_AM.png", "Screen Shot 2018-01-29 at 12.18.30 AM.png", 1048, 614, "#3a4b5d" ] } ] } [/block] Once created, you will be taken to the network campaign screen where you need to fill in THREE fields * **Adapter Class Name** (The class name of the Polymorph SDK adapter in your app integration) * **Placement ID** key's value is your placement that Facebook gives after you register your app with them. * **App Token** can be found on facebook dashboard [block:image] { "images": [ { "image": [ "https://files.readme.io/dd7e465-Screen_Shot_2018-01-29_at_12.25.24_AM.png", "Screen Shot 2018-01-29 at 12.25.24 AM.png", 1372, 980, "#eeeff0" ] } ] } [/block] **MoPub** 1. The easiest way to integrate MoPub SDK is by adding following lines to your gradle dependencies. [block:code] { "codes": [ { "code": "dependencies {\n compile('com.mopub:mopub-sdk-base:4.11.0@aar')\n compile('com.mopub:mopub-sdk-native-static:4.11.0@aar')\n compile('com.mopub.volley:mopub-volley:1.1.0@aar')\n}", "language": "groovy" } ] } [/block] NOTE: MoPub SDK version supported is 4.0.0 & above. 2. Copy networks/MoPubAdNetwork.java from Polymorph SDK into your project. You must copy into **com.mopub.nativeads** package under **src/** Follow the same steps for setting up the network campaign on Polymorph dashboard as shown for Facebook NOTE: MoPub ads may not work if you copy mopub adapter class into a different package other than **com.mopub.nativeads** **InMobi** 1. Download InMobi SDK from InMobi portal and copy InMobi-5.x.x.jar to your project's lib folder. Add add the following line to your gradle dependencies. [block:code] { "codes": [ { "code": "\nrepositories {\n flatDir {\n dirs 'libs'\n }\n}\n// ...\ndependencies {\n compile(name:'InMobi-5.x.x', ext:'jar')\n}", "language": "groovy" } ] } [/block] NOTE: InMobi SDK version supported is 5.0.0 & above. 2. Copy networks/InMobiAdNetwork.java from Polymorph SDK into your project. You can copy into any java package under **src/** (example **com.xyz.networks.InMobiAdNetwork**) Follow the same steps for setting up the network campaign on Polymorph dashboard as shown on Facebook **Flurry** 1. Download InMobi SDK from InMobi portal and copy InMobi-5.x.x.jar to your project's lib folder. Add add the following lines to your gradle dependencies. [block:code] { "codes": [ { "code": "repositories {\n flatDir {\n dirs 'libs'\n }\n}\n// ...\ndependencies {\n compile(name:'FlurryAds-6.x.x', ext:'jar')\n compile(name:'FlurryAnalytics-6.x.x', ext:'jar')\n}", "language": "groovy" } ] } [/block] NOTE: Flurry SDK version supported is 6.1.0 & above. 2. Copy networks/FlurryAdNetwork.java from Polymorph SDK into your project. You can copy into any java package under **src/** (example **com.xyz.networks.FlurryAdNetwork**) Follow the same steps for setting up the network campaign on Polymorph dashboard as shown for Facebook **DFP** 1. The easiest way to integrate DFP SDK is by adding following lines to your gradle dependencies. [block:code] { "codes": [ { "code": "dependencies {\n compile 'com.google.android.gms:play-services-ads:11.4.0'\n compile 'com.google.android.gms:play-services-location:11.4.0'\n}", "language": "groovy" } ] } [/block] 2. Copy networks/DFPAdNetwork.java from Polymorph SDK into your project. You can copy into any java package under **src/** (example **com.xyz.networks.DFPAdNetwork**) Check this page on how to setup/enable API access for your DFP account (needing for pulling reports): https://developers.google.com/doubleclick-publishers/docs/start While adding the network, please note below: * **username** - application name in dfp * **password** - dfp network id * **access token** - content of json file downloaded in `Create authentication credentials` section here: https://developers.google.com/doubleclick-publishers/docs/start After adding the network, you could follow the same steps for setting up the network campaign on Polymorph dashboard as shown on Facebook. Please note that DFP custom template id is mandatory along with DFP placement id. We currently do not support the default DFP templates (app-install and content-ad), so we require you to create a custom template for the assets you want on the DFP dashboard, under Creatives -> Native Ad Formats. Please ensure you are using the following labels while defining a custom template, else you may not get the desired asset. Headline - this is the label our adapter uses for Title Body - this is the label our adapter uses for Summary IconImage - this is the label for icon image MainImage - this is the label for main image CallToAction - this is the label for call-to-action (CTA)