AndroidSDK_Manual_Infeed - goldspotmedia-dev/sdk GitHub Wiki
Android SDK Infeed型広告 実装手順
- GSMSDKの初期化
- 広告枠の設定
- 広告リクエスト
- 広告Viewを画面に配置
- 広告Viewの表示
(例文)
FrameLayout layout = null;
String zone_ = "1";
float adHeight_ = 0.0f;
Context ct = this;
@Override
protected void onCreate(Bundle savedInstanceState) {
layout = new FrameLayout(this);
setContentView(layout);
//手順1
GSMMovieManager.initGSMManager(getApplicationContext());
//手順2
WindowManager wm = (WindowManager)ct.getSystemService(Context.WINDOW_SERVICE);
Display disp = wm.getDefaultDisplay();
Point point = new Point(0, 0);
if (android.os.Build.VERSION.SDK_INT >= 14) {
disp.getSize(point);
} else {
point.set(disp.getWidth(), disp.getHeight());
}
float ratio = point.x / 320;
adHeight_ = 180 * ratio;
HashMap<String, String> set = new HashMap<String, String>() {{
put("zone", zone_); //広告枠ID
put("adtype", "1"); //広告タイプ("1":Infeed "2":Interstitial "3":Overlay)
put("defaultorientation", String.valueOf("2")); //全画面表示時のデフォルト向き("1":Portrait "2":LandScape)
put("defaultvolume", String.valueOf("1")); //デフォルト音量("0":mute "1":unmute)
put("height", String.valueOf(adHeight_)); //広告枠高さ
}};
ArrayList<HashMap<String, String>> settings = new ArrayList<HashMap<String, String>>();
settings.add(set);
//手順3
GSMMovieManager.request(settings);
GSMMovieManager.setListener(new myGSMMovieListener());
}
@Override
public void onDestroy() {
GSMMovieManager.setListener(null);
GSMMovieManager.removeZone(zone_);
super.onDestroy();
}
class myGSMMovieListener extends GSMMovieListener {
@Override
public void gsmMoviePrepared(String zoneId) {
((Activity)ct).runOnUiThread(new Runnable() {
@Override
public void run() {
//手順4
layout.addView(GSMMovieManager.getGSMView(zoneInfeed_), new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, (int)adHeight_));
//手順5
GSMMovieManager.showAd(zone_);
}
});
}
}