通常バナー広告の配置

広告の表示は、広告表示用のViewであるGNAdViewによって行われます。

サンプルコードを以下に示します。


package jp.co.geniee.gnadssdksample;

(省略…)

// 必要なクラスのimport
import jp.co.geniee.gnadsdk.common.GNAdLogger;
import jp.co.geniee.gnadsdk.banner.GNAdView;
import jp.co.geniee.gnadsdk.banner.GNAdSize;
import jp.co.geniee.gnadsdk.banner.GNTouchType;

public class GenieeSampleBanner extends Activity {

	private GNAdView adView;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_geniee_sample_banner);
		
		// GNAdViewの作成
		adView = new GNAdView(
			this,
			GNAdSize.W300H250,           //広告バナーのサイズ
			GNTouchType.TAP_AND_FLICK    //タッチ操作のタイプ
		);
		adView.setAppId("Your_Geniee_AppID");		// AppID を設定
		//adView.setLogPriority(GNAdLogger.INFO);	// Debugログ出力
		//adView.setGeoLocationEnable(true);		// Geo最適化、デフォルト:false
		// 広告Viewの追加
		final LinearLayout layout = (LinearLayout)findViewById(R.id.layout);
		layout.addView(adView, LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT);
	}
	
	@Override
	protected void onResume() {
		super.onResume();
		if(adView != null){
			// 広告のローテーション表示を開始
			adView.startAdLoop();
		}
	}
	
	@Override
	protected void onPause() {
		super.onPause();
		if(adView != null){
			// 広告のローテーション表示を停止
			adView.stopAdLoop();
		}
	}
	
	@Override
	protected void onDestroy() {
		if(adView != null){
			// 広告配置画面の参照を解放
			adView.clearAdView();
		}
		super.onDestroy();
	}
}

startAdLoopを呼び出すと、GNAdViewは広告のロードを開始し、ロードが完了すると自動的に広告のローテーション表示を開始します。広告のローテーション表示を停止するにはstopAdLoopを呼び出します。

GNAdViewの広告処理サイクルイベントに応じて処理を行いたい場合には、インターフェース「GNAdEventListener」を利用することができます。
処理を行う必要が無い場合はGNAdEventListenerを使用する必要はありません。

インタースティシャル広告の配置

広告の表示は、広告表示用のViewであるGNInterstitialによって行われます。

サンプルコードを以下に示します。

import jp.co.geniee.gnadsdk.common.GNAdLogger;
import jp.co.geniee.gnadsdk.interstitial.GNInterstitial;
import jp.co.geniee.gnadsdk.interstitial.GNInterstitial.GNInterstitialDialogListener;
import jp.co.geniee.gnadsdk.interstitial.GNInterstitial.GNInterstitialListener;


public class GenieeSampleBanner extends Activity implements GNInterstitialListener, GNInterstitialDialogListener, OnClickListener {
	GNInterstitial interstitial = null;
	private Button loadButton;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_geniee_sample_banner);

		loadButton = (Button) findViewById(R.id.button1);
		loadButton.setOnClickListener(this);

		/* AppID を設定し初期化 */
		interstitial = new GNInterstitial(this, Your_Geniee_AppID);
		// GNInterstitialListenerの設定
		interstitial.setListener(this);
		// GNInterstitialDialogListenerの設定
		interstitial.setDialoglistener(this);
		// Geo最適化、デフォルト:false
		//interstitial.setGeoLocationEnable(true);
		// Debugログ出力
		//interstitial.setLogPriority(GNAdLogger.INFO);	
		// assetsのサンプルファイルを読み込み
		String strHtml = getHtmlFile("inters_default_html_sample_android.txt");
		// (オプション)ネット接続不可能等場合、代替表示用DefaultHtml画面
		interstitial.setDefaultHtml(strHtml);
	}
	
	@Override
	protected void onResume() {
		super.onResume();
	}
	
	@Override
	protected void onPause() {
		super.onPause();
	}
	
	// Sample ボタンをクリックしたタイミングでインタースティシャル広告を表示
	@Override
	public void onClick(View view) {
		if (view == loadButton) {
			//インタースティシャル広告タグをロードする
			interstitial.load(this);
		}
	}

	//GNInterstitialListenerリスナーオーバーライド関数
	//インタースティシャル広告タグロード完了時の処理
	@Override
	public void onReceiveSetting() {
		//インタースティシャル広告画面起動処理開始
		boolean is_show = interstitial.show(this);
		if (is_show) {
			//アプリ側、広告画面起動する場合の処理を記述
		} else {
			//アプリ側、広告画面起動しない場合の処理を記述
		}
	}
	
	//GNInterstitialListenerリスナーオーバーライド関数
	//ネット接続不可能、配信キャッピング、広告在庫がない場合の処理
	@Override
	public void onFailedToReceiveSetting() {
		//アプリ側、処理を記述
	}
	
	//GNInterstitialDialogListenerリスナーオーバーライド関数
	//バックキーとバツボタン押下時の処理
	@Override
	public void onClose() {
		//アプリ側、処理を記述
	}
	
	//GNInterstitialDialogListenerリスナーオーバーライド関数
	//管理画面より設定したボタン押下時の処理
	@Override
	public void onButtonClick(int nButtonIndex) {
		//アプリ側、押下したボタン番号(nButtonIndex:1、2、...)を基づいて、処理を記述
	}

	private String getHtmlFile(String filename){  
        AssetManager as = getResources().getAssets();   
        InputStream is = null;  
        BufferedReader br = null;  
        StringBuilder sb = new StringBuilder();   
        try{  
            try {  
                is = as.open(filename);  
                br = new BufferedReader(new InputStreamReader(is));   
                String str;     
                while((str = br.readLine()) != null){     
                    sb.append(str);    
                }      
            } finally {  
                if (br != null) br.close();  
            }  
        } catch (IOException e) {  
            Toast.makeText(this, filename + "読み込み失敗!", Toast.LENGTH_SHORT).show();  
        }  
        return sb.toString();
    }
}

コード詳細は、インタースティシャル広告サンプルアプリを参照してください。

動画広告の配置

広告の表示は、広告表示用のViewであるGNAdVideoによって行われます。

サンプルコードを以下に示します。

import jp.co.geniee.gnadsdk.common.GNAdLogger;
import jp.co.geniee.gnadsdk.video.GNAdVideo;
import jp.co.geniee.gnadsdk.video.GNAdVideo.GNAdVideoListener;

public class GenieeSampleVideo extends Activity implements GNAdVideoListener, OnClickListener {
	GNAdVideo videoAd = null;
	private Button loadButton;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_geniee_sample_banner);

		loadButton = (Button) findViewById(R.id.button1);
		loadButton.setOnClickListener(this);

		// 動画広告のGeniee AppID を設定し初期化
		videoAd = new GNAdVideo(this, Your_Geniee_AppID);
		// 動画広告在庫がない時、代替インタースティシャル広告のGeniee AppID (オプション設定)
		videoAd.setAlternativeInterstitialAppID(Your_Geniee_AppID);
		// GNAdVideoListenerの設定
		videoAd.setListener(this);
		// 動画広告再生完了後画面自動閉じるモード、デフォルト:true
		//videoAd.setAutoCloseMode(false);            
		// Debugログ出力
		//videoAd.setLogPriority(GNAdLogger.INFO);    
		// Geo最適化、デフォルト:false
		//videoAd.setGeoLocationEnable(true);         
		// 広告のフリークエンシー(何%の確率で表示):0〜100の数字を設定、未設定場合デフォルト100
		//videoAd.setShowRate(100);                   
		// 一回の起動あたりの最大表示回数:0以上の数字を設定、未設定場合デフォルト0(制限無し)
		//videoAd.setShowLimit(0);                    
		// 一回の起動あたりの最大表示回数のリセット分数:0以上の数字を設定、未設定場合デフォルト0(無効)
		//videoAd.setShowReset(0);                    
	}
	
	@Override
	protected void onResume() {
		super.onResume();
	}
	
	@Override
	protected void onPause() {
		super.onPause();
	}
	
	// Sample ボタンをクリックしたタイミングでインタースティシャル広告を表示
	@Override
	public void onClick(View view) {
		if (view == loadButton) {
			//動画広告タグをロードする
			videoAd.load(this);
		}
	}

	//GNAdVideoListenerの実装関数
	//動画タグ受信成功のイベントの処理
	@Override
	public void onGNAdVideoReceiveSetting() {
		//動画広告画面起動処理開始
		boolean is_show = videoAd.show(this);
		if (is_show) {
			//アプリ側、広告画面起動する場合の処理を記述
		} else {
			//アプリ側、広告画面起動しない場合の処理を記述
		}
	}
	
	//GNAdVideoListenerの実装関数
	//動画広告タグ受信失敗のイベント
	//ネット接続不可能、配信キャッピング、広告在庫がない場合の処理
	@Override
	public void onGNAdVideoFailedToReceiveSetting() {
		//アプリ側、処理を記述
	}
	
	//GNAdVideoListenerの実装関数
	//動画画面終了のイベントの処理
	@Override
	public void onGNAdVideoClose() {
		//アプリ側、処理を記述
	}
	
	//GNAdVideoListenerの実装関数
	//代替インタースティシャル広告の管理画面より設定したボタン押下時の処理
	@Override
	public void onGNAdVideoButtonClick(int nButtonIndex) {
		//アプリ側、押下したボタン番号(nButtonIndex:1、2、...)を基づいて、処理を記述
	}
}

コード詳細は、動画広告サンプルアプリを参照してください。