Android SDK Guide

14 minute read

Minah Kim

The current version is 105.

Sample Project

Android Studio Version
Bitbucket
git clone https://mezzomedia_adtech@bitbucket.org/mezzomediaadtech/android-studio_version.git
Eclipse Version
Bitbucket
git clone https://mezzomedia_adtech@bitbucket.org/mezzomediaadtech/android-eclipse_version.git

Intro

Ad type

Type Sample Description
standard banner typical bar banner
It is located mostly at the bottom, but can also be published at the top or in the middle, depending on the adjustments made by the publisher.
interstitial When an app is running, ads are posted on the front page, and publishers can adjust the exposure area.
interstitialvideo When an app is running, interstitialvideo are posted on the page.
interstitialEnd At the end of the app, an ad is posted on the front page and shows the App exit dialog at the bottom of the ad.
video This is a video advertisement that is played in the form of Pre-Roll before playing video content.
interstitialexpand When the app is launched, a full-page advertisement is posted, and the remaining area is filled with colors based on the top left hand corner 1 pixel.

Common setting

SDK library applying

The environment settings for Android development are skipped.
Create the Android Project you want to develop.
Create libs folder to add the provided mplus_sdk.jar.

AndroidManifest.xml setting

Register ‘com.mapps.andArray.view.InterstitialView’ as Activity.
android.permission is the required permission settings for inserting ad SDK.
android:configChanges=”orientation|keyboard” must be inserted in the attribute of the Activity to which you want to insert the ad.
 (To avoid wasting network resources due to continuous OnCreate calls)
Beginning with android9 (API 28), the value (android: usesCleartextTraffic = ”true”) is inserted into the application due to the enhanced network security policy.
Insert the option as the url load, tracking element, and resource can be http configured.
If you want to use Translucent or Floating activity in android8 (API 27), setting android: screenOrientation = “portrait” to activity style will result in an error. I am applying a style by version.

<?xml version="1.0" encoding="UTF-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.mplus.sdk.sample.release " android:versionCode="1" android:versionName="1.0">
<!--Because the url load, tracking element, and resource may be http configured, insert this option (android: usesCleartextTraffic = "true")-->
	<application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true" android:usesCleartextTraffic="true">
		<activity android:name=". MainActivity" android:label="@string/app_name" android:configChanges="orientation|keyboard">
			<intent-filter>
				<action android:name="android.intent.action.MAIN" />
				<category android:name="android.intent.category.LAUNCHER" />
			</intent-filter>
		</activity>
		<activity android:name="com.mapps.android.view.InterstitialView" android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" android:screenOrientation="portrait" />
	</application>
	<!--Network usage-->
	<uses-permission android:name="android.permission.INTERNET" />
	<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
	<!--Use position value-->
	<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
	<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
	<!--Use terminal information (TelecomyManager's MNC, MCC)-->
	<uses-permission android:name="android.permission.READ_PHONE_STATE" />
	<uses-sdk android:minSdkVersion="8" />
</manifest>

Res/attrs.xml Creating and Setting Up Files

<?xml version="1.0" encoding="UTF-8"?>
<resources>
	<declare-styleable name="com.mapps.android.view.AdView">
		<attr name="locationType" format="integer" />
		<attr name="backgroundStretch" format="integer" />
		<attr name="publisherCode" format="string" />
		<attr name="mediaCode" format="string" />
		<attr name="sectionCode" format="string" />
	</declare-styleable>
	<declare-styleable name="com.mapps.android.view.EndingAdView">
		<attr name="pCode" format="string" />
		<attr name="mCode" format="string" />
		<attr name="sCode" format="string" />
	</declare-styleable>
</resources>

Resource used for banner ads.
Set the name of declare-style to com.mapps.andClone.view.AddView.
Set attribute.

Name Description
publisherCode publisher code issued by Mezzomedia mobile business team
mediaCode media code issued by Mezzomedia mobile business team
sectionCode section code issued by Mezzomedia mobile business team
backgroundStretch The background area of the advertisement area is all painted in the corresponding advertisement color.
locationType the function to select the location of an ad area

Resource used for interstitialend banner
Set the name of declare-style to com.mapps.andClone.view.AddView.
Set attribute.

Name Description
pCode publisher code issued by Mezzomedia mobile business team
mCode media code issued by Mezzomedia mobile business team
sCode section code issued by Mezzomedia mobile business team

SDK guide

standard banner

The way Layout is set

input SDK App ID
Set the following code to the activity you want to insert an ad.

Name Description
xmlns:app Set the name of project package.
android:id It must be set and set to unique id value.
<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/background_light" android:orientation="vertical">
	<LinearLayout android:id="@+id/layout_gallery" android:layout_width="fill_parent" android:layout_height="50dp" android:orientation="vertical" />
	<com.mapps.android.view.AdView xmlns:app="http://schemas.android.com/apk/res/com.mplus.sdk.sample.release" android:id="@+id/ad" android:layout_width="match_parent" android:layout_height="20dp" app:backgroundStretch="0" app:locationType="0" app:mediaCode="201" app:mediaType="1" app:publisherCode="101" app:sectionCode="308" />
	<SurfaceView android:layout_width="0px" android:layout_height="0px" />
</RelativeLayout>

Import com.mapps.andArray.view to the Activity where the ad was inserted.
Override OnPause,OnResume of Acitivity.
After getting AdView’s object based on set android:id, call the StopService and StartService functions to OnPause and OnResume.
If multiple ads are inserted, they must be set for each ID.

package com.mplus.sdk.sample.release;

import com.mapps.android.view.AdView;
import com.mz.common.listener.AdListener;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.LinearLayout;

public class BannerSample extends Activity implements AdListener {
	private AdView m_adView = null;
	private LinearLayout bLayout = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.layout_banner);
		createBannerXMLMode();
	}

	private void createBannerXMLMode() {
		m_adView = (AdView) findViewById(R.id.ad);
		m_adView.setUserAge("1");
		m_adView.setUserGender("3");
		m_adView.setEmail("few.com");
		m_adView.setAccount("id");
		m_adView.setUserAgeLevel("0");
		m_adView.setStoreurl("http://store.url");
		m_adView.setKeyword("");
		m_adView.setExternal("");
		m_adView.setLoaction(false);
		m_adView.setAdListener(this);
	}

	@Override
	protected void onResume() {
		super.onResume();
		if (m_adView != null)
			m_adView.StartService();
	}

	@Override
	protected void onPause() {
		super.onPause();
		if (m_adView != null)
			m_adView.StopService();
	}

	@Override
	protected void onDestroy() {
		m_adView = null;
		if (bLayout != null)
			bLayout.removeAllViews();
		
		super.onDestroy();
	}

	public void onInterClose(View v) {

	}

	public void onAdClick(View v) {
	
	}

	public void onChargeableBannerType(View v, boolean bcharge) {
		Utils.onChargeableBannerType(bcharge);
	}

	public void onFailedToReceive(View v, int errorCode) {
		// Called if ad received successfully.Receive value 0 means success.
		Utils.customErrorMsg(errorCode, new Handler() {
			@Override
			public void dispatchMessage(Message msg) {
				String log = String.valueOf(msg.obj);
				Utils.log(log);
			}
		});
	}
}

You can enter the user’s information and collect data for that purpose.(Optional)
Refer to User info

m_adView.setUserAge("1");
m_adView.setUserGender("3");
m_adView.setEmail("few.com");
m_adView.setAccount("id");
m_adView.setUserAgeLevel("0");
m_adView.setStoreurl("http://store.url");
m_adView.setKeyword("");
m_adView.setExternal("");
m_adView.setLoaction(false);
How Java is set

Add Activity source

public class BannerSample extends Activity implements AdListener {
	AdView m_adView = null;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.layout_banner);
		String p = "100";
		String m = "200";
		String s = "300";
		createBannerJavaCodeView(p, m, s, AdInfoKey.TYPE_HTML);
	}

	public void createBannerJavaCodeView(String p, String m, String s, int type) {
		if (m_adView == null) {
			try {
				m_adView = new AdView(BannerSample.this, 0, 0, type);
				m_adView.setAdViewCode(p, m, s);
				m_adView.setUserAge("1");
				m_adView.setUserGender("3");
				m_adView.setEmail("few.com");
				m_adView.setAccount("id");
				m_adView.setUserAgeLevel("0");
				m_adView.setStoreurl("http://store.url");
				m_adView.setKeyword("");
				m_adView.setExternal("");
				m_adView.setLoaction(false);
				m_adView.setAdListener(this); // Register Listner
				bLayout = (LinearLayout) findViewById(R.id.layout_gallery);
				bLayout.addView(m_adView);
			} catch (Exception e) {
				m_adView = null;
				e.printStackTrace();
			}
		}
	}
	@Override
	protected void onResume() {
		super.onResume();
		if (m_adView != null)
			m_adView.StartService();
	}

	@Override
	protected void onPause() {
		super.onPause();
		if (m_adView != null)
			m_adView.StopService();
	}

	@Override
	protected void onDestroy() {
		m_adView = null;
		if (bLayout != null) {
			bLayout.removeAllViews();
		}
		super.onDestroy();
	}

	public void onChargeableBannerType(View v, boolean bcharge) {
		// If the ad received is free, the bcarge value is false
		if (m_adView == v) {
			if (bcharge) {
				Log.v("ADSDK", "-------> chargeable advertise !!!");
			} else {
				Log.v("ADSDK", "-------> Non chargeable advertise !!");
			}
		}
	}

	public void onFailedToReceive(View v, int errorCode) {
		// Called if ad received successfully.Receive value 0 means success
		if (m_adView == v) {
			Log.e("ADSDK", "-------> errorCode=" + errorCode);
			final int errcode = errorCode;
			handler.post(new Runnable() {
				public void run() {
					showErrorMsg(errcode);
				}
			});
		}
	}

	private void showErrorMsg(int errorCode) {
		String log;
		switch (errorCode) {
			case AdInfoKey.AD_SUCCESS:
				log = "[ " + errorCode + " ] " + "ad success";
				break;
			case AdInfoKey.AD_ID_NO_AD:
				log = "[ " + errorCode + " ] " + "no ad";
				break;
			case AdInfoKey.NETWORK_ERROR:
				log = "[ " + errorCode + " ] " + "(ERROR)network";
				break;
			case AdInfoKey.AD_SERVER_ERROR:
				log = "[ " + errorCode + " ] " + "(ERROR)server";
				break;
			case AdInfoKey.AD_API_TYPE_ERROR:
				log = "[ " + errorCode + " ] " + "(ERROR)API yype error";
				break;
			case AdInfoKey.AD_APP_ID_ERROR:
				log = "[ " + errorCode + " ] " + "(ERROR)ID error";
				break;
			case AdInfoKey.AD_WINDOW_ID_ERROR:
				log = "[ " + errorCode + " ] " + "(ERROR)ID error";
				break;
			case AdInfoKey.AD_ID_BAD:
				log = "[ " + errorCode + " ] " + "(ERROR)ID error";
				break;
			case AdInfoKey.AD_CREATIVE_ERROR:
				log = "[ " + errorCode + " ] " + "(ERROR)unable to generate ad";
				break;
			case AdInfoKey.AD_ETC_ERROR:
				log = "[ " + errorCode + " ] " + "(ERROR)exception error";
				break;
			case AdInfoKey.CREATIVE_FILE_ERROR:
				log = "[ " + errorCode + " ] " + "(ERROR)file type";
				break;
			case AdInfoKey.AD_INTERVAL:
				log = "[ " + errorCode + " ] " + "ad request abusing";
				break;
			case AdInfoKey.AD_TIMEOUT:
				log = "[ " + errorCode + " ] " + "ad API TIME OUT";
				break;
			case AdInfoKey.AD_ADCLICK:
				log = "[ " + errorCode + " ] " + "ad click";
				break;
			default:
				log = "[ " + errorCode + " ] " + "etc";
				break;
		}
		debug(log );
	}

	private void debug(String msg) {
		Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_LONG).show();
	}
	public void onInterClose(View v) {
		// interstitial close
	}
	public void onAdClick (View v) {
		//ad click
	}
}
Method Description
AdView (Context context, int backstrech, int locationType,int media_type) Refer to adview.
setAdViewCode (String publisher, String media, String section) Code issued by MezzMedia, Refer to ad code.
StartService() ad logic start
StopService() ad logic stop
setAdListener(AdListener listener) ad status event

AdView

Element Description
backstretch The background area of the advertisement area is all painted in the corresponding advertisement color.( 0 : Transparent 1 : BackgroundStretch )
locationType The function to select the location of an ad area.( 0 is center, 1 is left, 2 is right )
media_type This is a function to select an ad type. ( 0 is html form, 1 is image form )

Interstitial

How Java is set
AdInterstitialView m_interView = new AdInterstitialView ();
m_interView. setAdViewCode ("34", "227", "480"); 
m_interView.setUserAge("10");
m_interView.setViewStyle(VIEWSTYLE.NONE);
m_interView.setUserGender("1");
m_interView.setLoaction(true);
m_interView.setAccount("test");
m_interView.setEmail("test@mezzomediaco.kr");
m_interView.setUserAgeLevel("0");
m_interView.setStoreurl("http://store.url");
m_interView.setKeyword("");
m_interView.setExternal("");
m_interView.ShowInterstitialView();
Method
Method Description
setAdViewCode (String publisher, String media, String section) Code issued by Mezzomedia, Refer to ad code.
setViewStyle(int viewStyle) Refet to setViewStyle
ShowInterstitialView() A method that drives a interstitial banner

setViewStyle

Name Description
VIEWSTYLE.RESIZE pop-up
VIEWSTYLE.NONE full screen extension default value

interstitialend

How Java is set
FrameLayout ending_ad = (FrameLayout) findViewById(R.id.ending_ad);

m_flexibleAD = new EndingAdView(getContext(), mediaType);
m_flexibleAD.setAdViewCode(p, m, s);
m_flexibleAD.setBannerSize(250, 300);
m_flexibleAD.setAccount("id");
m_flexibleAD.setEmail("few.com");
m_flexibleAD.setUserAgeLevel("0");
m_flexibleAD.setStoreurl("http://store.url");
m_flexibleAD.setKeyword("");
m_flexibleAD.setExternal("");
ending_ad.addView(m_flexibleAD);

if (m_flexibleAD != null) {
	m_flexibleAD.startEndingAdView();
}
Method
Method Description
setAdViewCode (String publisher, String media, String section) Code issued by Mezzomedia, Refer to ad code.
setBannerSize(int w, int h) banner area size
startEndingAdView() A method that drives a interstitialend banner

Movie

How Java is set
// player definition
private void createAdPlayer(){
	adPlayer = (AdVideoPlayer)findViewById(R.id.ad_player);
	adPlayer. setCateContent("","");
	adPlayer.setLoaction(true);
	adPlayer.setAccount("id");
	adPlayer.setEmail("app@mezzomediaco.kr");
	adPlayer.setUserAgeLevel("0");
	adPlayer.setStoreurl("http://store.url");
	adPlayer.setKeyword("");
	adPlayer.setExternal("");	
	adPlayer.setAdVideoPlayerErrorListener (this);
	adPlayer.setAdVideoPlayerListener (this);
	adPlayer.setVideoMode(AdVideoPlayer.MODE_NORMAL);
	adPlayer.showAd();
}

// Player definition according to Activity Life cycle
@Override
protected void onDestroy() {
	super.onDestroy();

	if(adPlayer!=null)
		adPlayer.onDestory();
}
@Override
protected void onPause() {
	super.onPause();
	bActivate = false;

	if(adPlayer!=null)
		adPlayer.onPause();
}
@Override
protected void onResume() {
	super.onResume();

	if(!bActivate) {
		if(adPlayer!=null)
			adPlayer.onResume();
	}
}
	
@Override
public void onBackPressed() {
	super.onBackPressed();
	
	if(adPlayer!=null)
		adPlayer.onBackPressed();
}
<FrameLayout android:id="@+id/layout_player" android:layout_width="match_parent" android:layout_height="match_parent"	android:layout_weight="1" android:background="#000000">
	<VideoView android:id="@+id/videoViewExample" android:layout_width="match_parent" android:layout_height="match_parent" android:visibility="invisible" android:layout_gravity="center" />
	<com.mapps.android.main.AdVideoPlayer android:id="@+id/ad_player" android:layout_width="match_parent" android:layout_height="match_parent"/>
</FrameLayout>

Call onPause,onResume, etc. of the AdVideoPlayer class depending on the activity life cycle in which you have the player.
Play this player video in onAdPlayerReceive.

Method
Method Description
setAdViewCode (String publisher, String media, String section) Code issued by Mezzomedia,Refer to ad code.
setEmail(String str) Set the user’s email.
setLoaction(Boolean is) select GSP. (GPS_USE refers to whether or not to use location information. When set to false, GPS is not used.)
setVideoMode(int mode) Refer to ScreenMode.
setCateContent(String cate, String content) Set category name and category value
setAdVideoPlayerErrorListner (AdVideoPlayerErrorListener listener) VideoView Error Event
showAd(); ad start function
getVideoCurrentDuration() Returns the current playback time if called during video play. playtime sec = millisec /1000
onResume() call in case of resume event in Activity
onPause() call in case of onPause event in Activity
onBackPressed() call in case of onBackPressed event in Activity

Common points

User info

The standard banner, interstitial banner, interstitialend banner, and video banner have the following common functions.
 The following functions send information to the server for targeting and can be set as needed.

Method Description
setUserAge(String str) setting user age
setUserGender(String str) setting user gender ( 1 : male, 2 : female)
setAccount(String str) setting user account
setEmail(String str) setting user e-mail
setLoaction(Boolean is) GPS select function (GPS_USE refers to whether or not to use location information. When set to false, GPS is not used.)
setUserAgeLevel(String str) The user’s age level
(0: Children (13 years old or younger), 1: Youth / Adult (13 years old or older))
setStoreurl(String str) store url
setKeyword(String str) Pass keyword value
Separators are used as ^
keyword value is encoded
setExternal(String str) When using extended parameters
(You need to be guided when using additional parameters.)
ad code

This is common to the method in which the ad is inserted.

Element Description
publisher publisher code
media media code
section section code
Screen Mode

video ad screen mode

Screen mode Description
AdVideoPlayer.MODE_NORMAL 4:3 mode
AdVideoPlayer.MODE_WIDE 16:9 mode
AdVideoPlayer.MODE_STRETCH Fit to ParentView Size
AdVideoPlayer.MODE_ORIGNAL actual movie size
How to use AdListener
package com.mezzo.samplesdk;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import com.mapps.android.view.AdView;
import com.mapps.android.listner.AdListner;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleAdapter; 
public class BannerSample extends Activity implements AdListener {
	private AdView m_adlayout = null; 
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.layout_banner);
		m_adlayout= (AdView)findViewById(R.id.ad);
		m_adlayout.setAdListener(this);				
	}
	@Override
	protected void onPause() {
		super.onPause();
		
		if(m_adlayout !=null)
			m_adlayout.StopService();
	}
	@Override
	protected void onResume() {
		super.onResume();
		
		if(m_adlayout !=null)	
			m_adlayout.StartService();
	}
	public void onChargeableBannerType(View v, boolean bcharge) {
		/*
		* (bcharge value 'true' is commercial advertisement,'false' is free)
		*/
		if(m_adlayout == v) {
			if(bcharge) {
				Log.v("ADSDK", "-------> chargeable advertise !!!");
			} else {
				Log.v("ADSDK", "-------> Non chargeable advertise !!");
			}
		}
	}
	public void onFailedToReceive(View v, int errorCode) {
		if(m_adlayout == v) {
			switch(errorCode) {
				case AdInfoKey.AD_SUCCESS:
					// ad success
					break;
				case AdInfoKey. AD_ID_NO_AD:
					// no ad
					break;
				case AdInfoKey. NETWORK_ERROR:
					// (ERROR)network
					break;
				case AdInfoKey. AD_SERVER_ERROR:
					// (ERROR)server
					break;
				case AdInfoKey. AD_API_TYPE_ERROR:
					// (ERROR)API type error
					break;
				case AdInfoKey. AD_APP_ID_ERROR:
					//(ERROR)ID error
					break;
				case AdInfoKey. AD_WINDOW_ID_ERROR:
					//(ERROR)ID error
					break;
				case AdInfoKey. AD_ID_BAD:
					//(ERROR)ID error
					break;
				case AdInfoKey. AD_CREATIVE_ERROR:
					//(ERROR)unable to generate ad
					break;
				case AdInfoKey. AD_ETC_ERROR:
					//(ERROR)exception error
					break;
				case AdInfoKey. CREATIVE_FILE_ERROR:
					//(ERROR)file type
					break;
				case AdInfoKey. AD_INTERVAL:
					// ad request abusing
					break;
				case AdInfoKey. AD_TIMEOUT:
					// ad API TIME OUT
					break;
				case AdInfoKey. AD_ADCLICK:
					// ad click
					break;
				default:
					break;
			}		
		}
	}
	public void onAdClick (boolean b) {
		//ad click
	}

	public void onInterClose (View view) {
		//interstitial close event
	}
}

Add AdListner as an implements.
register setAdListner

AdListener description
Method Description
onChargeableBannerType(View v, boolean bcharge) This is an event that will be passed if you register a listner. If bcharge is true, it will be free, if it is false, it will be commercial advertisement.
onFailedToReceive(View v, int errorCode) This event occurs when an error occurs.
Refer to Listener Code.
onInterClose (View v) interstitial close event
onAdClick(View v) banner ad click event
Listener Code
Code Description
0 success
3 ad click
-100 network error
-200 ad server error
-300 API type error
-400 app ID value error
-500 Window ID value error
-600 the ID value is not normal
-700 Ads for that ID do not exist
-800 unexpected exception
-900 ad creativbe error
-1000 Exclude ad calls because it takes set interval time
-2000 timeout

Help

Q&A

check whether an ad is exposed successfully
No Description
1 Q. How to check if an advertisement is not exposed after applying SDK
A. SDK can be implemented in XML and Java code, so you can check whether the correct code is set in the way it is implemented.
2 Q. If there are no ads or free ads after the set of commercial advertisement
A. The error of advertising exposure after you set up an ad is largely due to the incorrect code or to the test code. Please check the setting.
If you are unable to see the commercial advertisement continuously, Please contact us.
handling No ad (passback)
No Description
1 Q. No ad handling questions
A. If the ad assigned to that ID does not exist or runs out of stock, or
 depending on time, application type, category, and date, the number of ads that can also be exposed may vary
 After a certain period of time, you can request an advertisement again or proceed to the next progressive logic in the part where you received the callback.
2 Q. Why do I see the figures in the report even in the No ad situation?
A. Even under No ad, the report number is normal, which is the call number for inventory check, not for actual exposure.

Contact

Division Team Name E-mail Contact
affiliated inquiry Mobile business Gwon Heo gwon.heo@cj.net +82) 02-6484-3649
ID issue and ad setting Mobile business Yeonjong Ryu yj.ryu@cj.net +82) 02-6484-3282

Updated: