- Android 1.5 or later.
- Swelen Android SDK for Swelen Magnet and MobileManager (obviously).
- Your slot UID from Swelen: To find your slot UID, log into your Swelen account, select "Applications" then click on your application.
Download the latest Android SDK and unzip it.
If you are using Eclipse:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.swelends.ads.example"
android:versionCode="1"
android:versionName="1.0">
<application android:label="@string/app_name" >
<activity android:name="SwelenAdsExample"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.swelen.ads.SwelenAdActivity"
android:theme="@android:style/Theme.Translucent"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
</application>
</manifest>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.swelends.ads.example"
android:versionCode="1"
android:versionName="1.0">
<application android:label="@string/app_name" >
<activity android:name="SwelenAdsExample"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.swelen.ads.SwelenAdActivity"
android:theme="@android:style/Theme.Translucent"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
</application>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
</manifest>
import android.app.Activity;
import android.os.Bundle;
import android.widget.LinearLayout;
import com.swelen.ads.SwelenAdView;
public class SwelenAdsExample extends Activity
{
private SwelenAdView adView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//Instantiate a new SwelenAdView
adView = new SwelenAdView(this, YOUR_SLOT_UID);
//Lookup your layout, assuming it's been given the attribute android:id="@+id/mainLayout"
LinearLayout layout = (LinearLayout)findViewById(R.id.mainLayout);
//Add the SwelenAdView to your layout
layout.addView(adView);
}
@Override
public void onDestroy() {
super.onDestroy();
adView.destroy();
}
@Override
protected void onResume() {
super.onResume();
adView.resume();
}
@Override
protected void onPause() {
super.onPause();
adView.pause();
}
}
import android.app.Activity;
import android.os.Bundle;
import android.widget.LinearLayout;
import com.swelen.ads.SwelenAdView;
public class SwelenAdsExample extends Activity
{
private SwelenAdView adView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//Instantiate a new SwelenAdView
adView = new SwelenAdView(this, YOUR_SLOT_UID);
}
@Override
public void onDestroy() {
super.onDestroy();
adView.destroy();
}
}
import android.util.Log;
import android.app.Activity;
import android.os.Bundle;
import android.widget.LinearLayout;
import com.swelen.ads.SwelenAdView;
import com.swelen.ads.SwelenAdListener;
public class SwelenAdsExample extends Activity implements SwelenAdListener
{
private SwelenAdView adView;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//Instantiate a new SwelenAdView
adView = new SwelenAdView(this, YOUR_SLOT_UID);
adView.setAdListener(this);
//Lookup your layout, assuming it's been given the attribute android:id="@+id/mainLayout"
LinearLayout layout = (LinearLayout)findViewById(R.id.mainLayout);
//Add the SwelenAdView to your layout.
layout.addView(adView);
}
public Boolean onAdLoaded(SwelenAdView v) {
Log.d("DemoDebug", "onAdLoaded called");
return true;//Display the ad right away
}
public void onAdShow(SwelenAdView v) {
Log.d("DemoDebug", "onAdShow called");
}
public void onAdError(SwelenAdView v, int error) {
Log.e("DemoDebug", "onAdError : " + error);
}
public void onAdClose(SwelenAdView v) {
Log.d("DemoDebug", "onAdClose called");
}
public void onAdClick(SwelenAdView v) {
Log.d("DemoDebug", "onAdClick called");
}
}
SwelenAdView adView = new SwelenAdView(this, YOUR_SLOT_UID, location);
The user's location must be obtained by a suitable method.
SwelenAdView adView = new SwelenAdView(this, YOUR_SLOT_UID, location);
adView.setAutoClose(false);
import android.app.Activity;
import android.os.Bundle;
import android.widget.LinearLayout;
import com.swelen.ads.SwelenAdConversion;
public class SwelenAdsExample extends Activity
{
private SwelenAdView adView;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
SwelenAdConversion conversion = new SwelenAdConversion(this, YOUR_CONVERSION_UID, SwelenAdConversion.UNIQUE);
}
}
The following conversion modes are available:
import android.util.Log;
import android.app.Activity;
import android.os.Bundle;
import com.swelen.ads.SwelenAdConversion;
import com.swelen.ads.SwelenAdConversionListener;
public class SwelenAdsExample extends Activity
{
private SwelenAdView adView;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
SwelenAdConversion conversion = new SwelenAdConversion(this, YOUR_CONVERSION_UID, SwelenAdConversion.UNIQUE);
conversion.setListener(this);
}
public void onAdConversion() {
Log.d("DemoDebug", "Conversion done!");
}
public void onAdConversionError(int error) {
Log.d("DemoDebug", "Conversion error : " + error);
}
}