「Android Interstitial Ads 2.0」修訂間的差異
跳至導覽
跳至搜尋
imported>Wikiuser |
imported>Wikiuser |
||
(未顯示同一使用者於中間所作的 4 次修訂) | |||
行 1: | 行 1: | ||
: | == <b>簡介</b> == | ||
TWMInterstitialAd為全螢幕大小之廣告, 使用方法跟TWMAdView非常類似, 顯示廣告時需在onReceivedAd()之後呼叫show()函式以便顯示<br/><b>注意:目前Interstitial廣告有相同版位ID在同一台裝置上,預設為120分鐘展示一次,如需調整請洽服務窗口</b> | :<span style="font-size:16px;">TWMInterstitialAd為全螢幕大小之廣告, 使用方法跟TWMAdView非常類似, 顯示廣告時需在onReceivedAd()之後呼叫show()函式以便顯示<br/><b>注意:目前Interstitial廣告有相同版位ID在同一台裝置上,預設為120分鐘展示一次,如需調整請洽服務窗口</b></span> | ||
TWMInterstitialAd twmInterstitial = new TWMInterstitialAd(this, | <br><br> | ||
<br> | |||
== <b>實作方式</b> == | |||
*<span style="font-size:16px;">廣告初始設置</span> | |||
TWMInterstitialAd twmInterstitial = new TWMInterstitialAd(this, <b>"{YOUR_AD_UNIT_ID}"</b>); | |||
<br><br> | |||
*<span style="font-size:16px;">加入TWMAdViewListener監聽廣告投放情況,並在onReceiveAd Callback內呼叫showAd()</span> | |||
:在<b>onReceiveAd</b>後可透過<b>showAd()</b>顯示廣告 | |||
twmInterstitial.setAdListener(new TWMAdViewListener() { | twmInterstitial.setAdListener(new TWMAdViewListener() { | ||
@Override | @Override | ||
行 19: | 行 28: | ||
public void onLeaveApplication(TWMAd paramTWMAd) {} | public void onLeaveApplication(TWMAd paramTWMAd) {} | ||
}); | }); | ||
<br><br> | |||
* | *<span style="font-size:16px;">建立 TWMAdRequest</span> | ||
// | :請求廣告前,你需要創建一個TWMAdRequest物件 | ||
TWMAdRequest request = new TWMAdRequest(); | |||
:若額外設置使用者生日,可讓您的APP獲得更多元的廣告內容<br> | |||
{| class="wikitable" | |||
|- | |||
! 使用Date !! 使用Calendar | |||
|- | |||
| style="width:60%; padding:1%;"| | |||
TWMAdRequest request = new TWMAdRequest(); | |||
try { | |||
<b>//定義好時間字串的格式</b> | |||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd", Locale.getDefault()); | |||
<b>//將字串轉成Date型</b> | |||
Date birthDate = sdf.parse("1992/01/01"); | |||
<b>// 將生日加入request</b> | |||
request.setBirthday(birthDate); | |||
}catch (Exception e) {} | |||
| style="width:40%; padding: 1%;"| | |||
<b>// 創建Calerdar並設定生日 (注意! 月份的編號是由0至11)</b> | |||
Calendar birthDate = Calendar.getInstance(); | |||
<b>// 設定生日為1992/01/01</b> | |||
birthDate.set(1992, 0, 1); | |||
<b>// 將生日加入request</b> | |||
TWMAdRequest request = new TWMAdRequest(); | TWMAdRequest request = new TWMAdRequest(); | ||
deviceId = getDeviceId(getBaseContext()); | request.setBirthday(birthDate); | ||
|} | |||
<br><br> | |||
*<span style="font-size:16px;">請求廣告</span> | |||
twmInterstitial.loadAd(request); | |||
*<span style="font-size:16px;">若需要進行廣告投放的測試,可使用測試模式來請求廣告, ※測試模式將不會紀錄任何的曝光以及點擊數據</span> | |||
String deviceId = getDeviceId(getBaseContext()); | |||
twmInterstitial.loadAd(new TWMAdRequest().addTestDevice(deviceId)); | |||
private String getDeviceId(final Context context) { | 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; | md5 = "0" + md5; | ||
return md5; | |||
} catch (NoSuchAlgorithmException e) { | |||
return null; | |||
} | |||
} | |||
<br><br> | |||
== Interstitial畫面展示 == | |||
{| border="1" | {| border="1" | ||
|- | |- | ||
行 70: | 行 107: | ||
| align="center" | [[檔案:device-2014-06-03-180204.png]] | | align="center" | [[檔案:device-2014-06-03-180204.png]] | ||
|} | |} | ||
<br><br> | |||
[[Android SDK Developer Guide 2 | 回首頁]] |
於 2021年11月16日 (二) 06:25 的最新修訂
簡介
- TWMInterstitialAd為全螢幕大小之廣告, 使用方法跟TWMAdView非常類似, 顯示廣告時需在onReceivedAd()之後呼叫show()函式以便顯示
注意:目前Interstitial廣告有相同版位ID在同一台裝置上,預設為120分鐘展示一次,如需調整請洽服務窗口
實作方式
- 廣告初始設置
TWMInterstitialAd twmInterstitial = new TWMInterstitialAd(this, "{YOUR_AD_UNIT_ID}");
- 加入TWMAdViewListener監聽廣告投放情況,並在onReceiveAd Callback內呼叫showAd()
- 在onReceiveAd後可透過showAd()顯示廣告
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) {} });
- 建立 TWMAdRequest
- 請求廣告前,你需要創建一個TWMAdRequest物件
TWMAdRequest request = new TWMAdRequest();
- 若額外設置使用者生日,可讓您的APP獲得更多元的廣告內容
使用Date | 使用Calendar |
---|---|
TWMAdRequest request = new TWMAdRequest(); try { //定義好時間字串的格式 SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd", Locale.getDefault()); //將字串轉成Date型 Date birthDate = sdf.parse("1992/01/01"); // 將生日加入request request.setBirthday(birthDate); }catch (Exception e) {} |
// 創建Calerdar並設定生日 (注意! 月份的編號是由0至11) Calendar birthDate = Calendar.getInstance(); // 設定生日為1992/01/01 birthDate.set(1992, 0, 1); // 將生日加入request TWMAdRequest request = new TWMAdRequest(); request.setBirthday(birthDate); |
- 請求廣告
twmInterstitial.loadAd(request);
- 若需要進行廣告投放的測試,可使用測試模式來請求廣告, ※測試模式將不會紀錄任何的曝光以及點擊數據
String deviceId = getDeviceId(getBaseContext()); twmInterstitial.loadAd(new TWMAdRequest().addTestDevice(deviceId));
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畫面展示
插頁式廣告呈現 |