-
Notifications
You must be signed in to change notification settings - Fork 0
Implementation Guide: Android SDK
This tutorial requires an activated AdFlake account as well as familiarity with Java, Android development and Eclipse project configuration.
If you have any questions, please take a look at the AdFlake-SampleApp that ships together with our official SDK release.
The following four steps will enable your Android application utilize AdFlake's features.
To leverage AdFlake your app must include the AdFlake SDK JAR. Add the AdFlake JAR into your project's build path.
To enable your app to support different ad networks, it is required to be signed up on the networks you want to support and including their SDK's jar in your project.
Of course it is also required to allocate enough traffic for an ad network through the ad network settings menu in your app specific page on AdFlake.
In order for our SDK to know which ad configuration to serve, you have to include your app's SDK key in your AndroidManifest.xml. You can find your app's SDK key on it's detail page on AdFlake.com.
Simply add a meta-data node with name=ADFLAKE_KEY and a value with your SDK key into the application node of your AndroidManifest.xml
<application>
<!-- .... your app's configuration --->
<meta-data android:name="ADFLAKE_KEY" android:value="YOUR_APPS_SDK_KEY_HERE" />
</application>
In order for your app to access the AdFlake service and ad networks it is necessary to add the internet access permission android.permission.INTERNET in your AndroidManifest.xml.
Some network SDKs may also utilize android.permission.ACCESS_COARSE and android.permission.FINE_LOCATION for location-based advertising and android.permission.READ_PHONE_STATE.
Several ad network SDKs require the inclusion of nodes that enable ad network specific activities. To make setup easier for you, we're listing the configurations for all networks on this page. For more details please refer to the SDK documentation of the specific ad networks you're interested in.
<!-- AdMob integration -->
<activity android:name="com.google.ads.AdActivity" android:configChanges="orientation|keyboard|keyboardHidden|screenLayout|uiMode|screenSize|smallestScreenSize" />
<!-- MdotM integration -->
<activity android:name="com.mdotm.android.view.MdotMActivity" android:launchMode="singleTop" android:screenOrientation="portrait" />
<!-- Millennial integration -->
<activity android:name="com.millennialmedia.android.MMActivity" android:configChanges="keyboardHidden|orientation|keyboard" android:theme="@android:style/Theme.Translucent.NoTitleBar" >
</activity>
<!-- InMobi integration -->
<activity android:name="com.inmobi.androidsdk.IMBrowserActivity" android:configChanges="keyboardHidden|orientation|keyboard|screenSize|smallestScreenSize" />
<!-- KomliMobile integration (Not functional currently due to major issues in their SDK!) -->
<activity android:name="com.komlimobile.sdk.KomliMobileActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
<!-- MobClix integration -->
<activity android:name="com.mobclix.android.sdk.MobclixBrowserActivity" android:theme="@android:style/Theme.Translucent.NoTitleBar" />
<!-- GreyStripe integration -->
<activity android:name="com.greystripe.sdk.GSFullscreenActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenSize" />
<!-- Amazon integration -->
<activity android:name="com.amazon.device.ads.AdActivity" android:configChanges="keyboardHidden|orientation|screenSize" />
<!-- Mobfox integration -->
<activity android:name="com.adsdk.sdk.banner.InAppWebView" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
<!-- AppBrain AppLift SDK - NOTE: only uncomment when AppBrain lib is included! -->
<!--
<activity android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" android:name="com.appbrain.AppBrainActivity" />
<receiver android:exported="false" android:name="com.appbrain.ReferrerReceiver" >
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
<service android:name="com.appbrain.AppBrainService" />
-->
That's it for the configuration of your app's manifest, if you've already included the AdFlake jar file and the jar files of the network you want to use. You're ready to go!
Finally, to display the mediated ads simply configure AdFlakeTargeting as appropriate and add an AdFlakeLayout to your Activity view hierarchy.
Simply create an instance of the AdFlakeLayout and insert it into your layout.
DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
final float density = displayMetrics.density;
final int width = (int) (AdFlakeUtil.BANNER_DEFAULT_WIDTH * density);
final int height = (int) (AdFlakeUtil.BANNER_DEFAULT_HEIGHT * density);
final String myAdFlakeSdkKey = "YOUR_ADFLAKE_SDK_KEY";
AdFlakeLayout adFlakeLayout2 = new AdFlakeLayout(this, myAdFlakeSdkKey);
adFlakeLayout2.setAdFlakeInterface(this);
adFlakeLayout2.setMaxWidth(width);
adFlakeLayout2.setMaxHeight(height);
layout.addView(adFlakeLayout2, adFlakeLayout2.getOptimalRelativeLayoutParams());
For further configuration options, like specifying ad targeting options, check out our provided sample application.
If you prefer to create your layouts using layout XML files, simply add an AdFlakeLayout to your layout XML. When using XML layouting, it is mandatory to specify your AdFlake SDK key in your AndroidManifest.xml
The following layout XML file shows how to add an AdFlakeLayout instance to your layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/layout_main" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="vertical" >
<com.adflake.AdFlakeLayout
android:id="@+id/adflake_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>