Android Interstitial Ads 2.0
於 2014年6月17日 (二) 03:04 由 imported>Wikiuser 所做的修訂
- 宣告Interstitial廣告版位
TWMInterstitialAd為全螢幕大小之廣告, 使用方法跟TWMAdView非常類似, 顯示廣告時需在onReceivedAd()之後呼叫show()函式以便顯示
注意:目前Interstitial廣告有相同版位ID在同一台裝置上,預設為120分鐘展示一次,如需調整請洽服務窗口
TWMInterstitialAd twmInterstitial = new TWMInterstitialAd(this, AD_UNIT_ID);
twmInterstitial.setAdListener(new TWMAdViewListener() {
@Override
public void onReceiveAd(TWMAd paramTWMAd) {
// 顯示 interstitial
if(paramTWMAd == twmInterstitial){
twmInterstitial.show();
}
}
@Override
public void onFailedToReceiveAd(TWMAd paramTWMAd, ErrorCode paramErrorCode) {}
@Override
public void onPresentScreen(TWMAd paramTWMAd) {}
@Override
public void onDismissScreen(TWMAd paramTWMAd) {}
@Override
public void onLeaveApplication(TWMAd paramTWMAd) {}
});
// 載入廣告
twmInterstitial.loadAd(new TWMAdRequest());
- 若需要進行廣告投放的測試,可以測試模式來請求廣告, ※測試模式將不會紀錄任何的曝光以及點擊數據
// 請在將要載入廣告所使用的TWMAdView / TWMInterstitialAd / TWMVideoAd 以下列的方式進行廣告請求, 下面以TWMAdView (Banner Ad)來進行示範
TWMAdView adView = new TWMAdView(this, {YOUR_ADUNIT_ID_BANNER});
TWMAdRequest request = new TWMAdRequest();
deviceId = getDeviceId(getBaseContext());
request.addTestDevice(deviceId); // 加入測試的手機Id
adView.loadAd(request);
private String getDeviceId(final Context context) {
String deviceId = null;
try {
deviceId = android.provider.Settings.Secure.getString(
context.getContentResolver(), Secure.ANDROID_ID);
if (deviceId!= null) {
return convertToMD5ID(deviceId);
}
} catch (Exception e) {
Log.e("getDeviceId", e.getMessage(), e);
}
return deviceId;
}
private String convertToMD5ID(final String string) {
if (string == null) {
return null;
}
try {
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(string.getBytes());
BigInteger number = new BigInteger(1, md.digest());
String md5 = number.toString(16);
while (md5.length() < 32)
md5 = "0" + md5;
return md5;
} catch (NoSuchAlgorithmException e) {
return null;
}
}
- Interstitial畫面展示
| 插頁式廣告呈現 |
|
