我一直在處理此代碼,顯然插頁式廣告和橫幅廣告無法加載。插頁式廣告和橫幅廣告無法加載
以下是創建橫幅廣告查看和添加新生成的廣告單元的代碼。同時它與AdListener的支持插頁式廣告的代碼,看看廣告的工作..
//Ads ----------------
// Create the adView
RelativeLayout layout = new RelativeLayout(this);
layout.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
//<!-- Ads Using Google Play Services SDK -->
adView = new AdView(this);
adView.setAdSize(AdSize.SMART_BANNER);
adView.setAdUnitId(AD_UNIT_ID);
// Add the adView to it
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
params.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE);
adView.setLayoutParams(params);
layout.addView(mGLSurfaceView);
layout.addView(adView);
setContentView(layout);
//New AdRequest
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
//-----------------------------------------------------Interstitial Add
// Create an Interstitial ad.
interstitialAd = new InterstitialAd(this);
interstitialAd.setAdUnitId(AD_INTERSTITIAL_UNIT_ID);
interstitialAd.loadAd(new AdRequest.Builder().build());
interstitialAd.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
interstitialAd.show();
}
@Override
public void onAdFailedToLoad(int errorCode) {
Toast.makeText(getApplicationContext(), "Interstitial Ads loading failed", Toast.LENGTH_SHORT).show();
}
});
// Load the interstitial ad.
showInterstitialAds();
public void showInterstitialAds()
{
runOnUiThread(new Runnable() {
public void run() {
AdRequest interstitialAdRequest = new AdRequest.Builder().build();
interstitialAd.loadAd(interstitialAdRequest);
}
});
}
在應用程序中,我得到的是吐司消息宣佈的插頁式廣告不起作用。即使橫幅廣告不起作用。 在logcat中,我得到不同的信息: 我最後得到:
01-17 16:54:05.765: I/Ads(1136): No fill from ad server.
01-17 16:54:05.769: I/Ads(1136): Scheduling ad refresh 60000 milliseconds from now.
01-17 16:54:05.769: W/Ads(1136): Failed to load ad: 3
而且有這樣的:
01-17 16:52:02.945: I/Ads(1136): Starting ad request.
01-17 16:52:02.945: I/Ads(1136): Use AdRequest.Builder.addTestDevice("A55B0AA295150C0583B3FADA0B02054B") to get test ads on this device.
我試圖在showInterstitialAds以上,但我一直收到的是同樣的錯誤和廣告沒不顯示。
而且,最有趣的是:
There was a problem getting an ad response. ErrorCode: 2
隨着對errocode不同的數字:0,2,3。我不確定這是什麼意思,因爲我是整個Android世界的新手(我剛剛在幾個月前開始編碼)。
你是什麼意思「它提供了糟糕的用戶體驗?」那麼這將是一個很好的替代方法? – Anas
查看更新的答案。糟糕的用戶體驗,因爲當用戶處於與您的應用程序相關的工作中時,廣告將會彈出,例如玩遊戲或輸入/消費信息。 – William
謝謝,明白了! – Anas