Skip to content

Implementation Guide: Android SDK

Manny edited this page Oct 5, 2013 · 5 revisions

AdFlake implementation on Android will boost your ad revenue by integrating up to 4 ad providers:

  • AdMob
  • Google AdSense
  • Millennial Media
  • ZestADZ

This tutorial requires a minimum familiarity with Java, Android development and Eclipse project configuration. Five steps will enable your application to gain AdFlake powered ad revenues.

1. AdFlake

To leverage AdFlake your app must include the AdFlake SDK JAR. Add the AdFlake JAR into your project path.

2. Ad Networks

To include ad networks it is required to be signed up on the different networks and including their SDK's into 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.

3. Permissions

In order for your app to access the AdFlake service and ad networks it must obviously have android.permission.INTERNET. Some network SDKs may also utilize android.permission.ACCESS_COARSE/FINE_LOCATION for location-based advertising and android.permission.READ_PHONE_STATE.

4. AdFlakeLayout

Finally, to display the mediated ads simply configure AdFlakeTargeting as appropriate and add an AdFlakeLayout to your Activity view hierarchy.

4.1 Java

public class HelloAdFlakel extends Activity implements AdFlakeInterface {
 public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.main);

   AdFlakeManager.setConfigExpireTimeout(1000 * 60 * 5);

   AdFlakeTargeting.setAge(23);
   AdFlakeTargeting.setGender(AdFlakeTargeting.Gender.MALE);
   AdFlakeTargeting.setKeywords("cute games birds");
   AdFlakeTargeting.setPostalCode("94123");
   AdFlakeTargeting.setTestMode(false);

   AdFlakeLayout adFlakeLayout = (AdFlakeLayout)findViewById(R.id.adflake_layout);

   TextView textView = new TextView(this);
   RelativeLayout.LayoutParams layoutParams = new
   RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                             LayoutParams.WRAP_CONTENT);
   int width = 320;
   int height = 52;
   int density = getResources().getDisplayMetrics().density;

   adWhirlLayout.setAdWhirlInterface(this);
   adWhirlLayout.setMaxWidth((int)(width * density));
   adWhirlLayout.setMaxHeight((int)(height * density));

   layoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
   textView.setText("Below AdFlakeLayout");

   LinearLayout layout = (LinearLayout)findViewById(R.id.layout_main);

   layout.setGravity(Gravity.CENTER_HORIZONTAL);
   layout.addView(adFlakeLayout, layoutParams);
   layout.addView(textView, layoutParams);
   layout.invalidate();
   }
  }

4.2 XML

While previous releases required direct AdFlakeLayout instantiation in order to provide a SDK key...

AdFlakeLayout adFlakeLayout = new AdFlakeLayout(this,
                                           "643eb700781e4f47b017ea27d1aba3be");

...this value may now be specified at either the application or activity level via the XML attribute ADFLAKE_KEY.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
 package="com.adflake" android:versionCode="1" android:versionName="1.0">
 <application android:icon="@drawable/icon" android:label="@string/app_name"
    android:debuggable="true">
    <activity android:name=".Invoker" android:label="@string/app_name">
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
      <meta-data android:value="643eb700781e4f47b017ea27d1aba3be"
        android:name="ADFLAKE_KEY"/>
    </activity>

Keys for specific layouts trump any application-level value.

5 Google AdSense for Mobile Applications Configuration

Google AdSense for Mobile Applications features one requirement and two options not currently supported by AdFlake’s adapter abstraction.

5.1 Company and App Names

Google AdSense for Mobile Applications requires company and app names uniquely identifying your app. Failure to provide these values via the AdWhirlAdapter statics setGoogleAdSenseCompanyName and setGoogleAdSenseAppName will disable AdSense ads.

5.2 AdSense Channel ID

You may optionally also specify an AdSense channel ID via AdWhirlAdapter.setGoogleAdSenseChannel to better track your app’s performance.

####5.3 Expandable Ads

Specifying an expand direction of either “BOTTOM” or “TOP” via AdFlakeAdapter.setGoogleAdSenseExpandDirection will enable AdSense’s expandable ads.

Clone this wiki locally