如何创建Android的广告间质性? [英] How to create android Ad Interstitial?
本文介绍了如何创建Android的广告间质性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在我的Android应用程序创建内广告,我尝试了许多博客,但没有人给一步的解决方案的步骤。 - 如果我编辑的东西上AdMob的网站吗?我创建的网站从广告静坐/应用程序选项下的网站和放大器;应用程序选项卡。 -I用这个code:
How to create Interstitial ad in my android app, I tried many blogs but no one give the step by step solution. - Should I edit something on adMob site? I created site from ad sit/app option under Sites & Apps tab. -I used this code:
interstitial = new InterstitialAd(this, "MyAdMobID");
// Set Ad Listener to use the callbacks below
interstitial.setAdListener(this);
// Create ad request
AdRequest adRequest = new AdRequest();
adRequest.addTestDevice(AdRequest.TEST_EMULATOR);
// Begin loading your interstitial
interstitial.loadAd(adRequest);
adRequest.setTesting(true);
亲切的问候提前。
Kind Regards in Advance.
穆罕默德
推荐答案
使用最后一个Android框架,我想通了,我需要调用load()的广告每次关闭功能。
Using the last Android framework, I figured out that I need to call the load() function each time the ad is closed.
import com.google.android.gms.ads.*;
import android.os.Handler;
import android.os.Looper;
import android.app.Activity;
class MyActivity extends Activity implements AdListener {
private InterstitialAd adView; // The ad
private Handler mHandler; // Handler to display the ad on the UI thread
private Runnable displayAd; // Code to execute to perform this operation
@Override
public void onCreate(Bundle savedInstanceState) {
adView = new InterstitialAd(mContext);
adView.setAdUnitId("ca-app-pub-XXXXXXXXXX");
adView.setAdListener(this);
mHandler = new Handler(Looper.getMainLooper());
displayAd = new Runnable() {
public void run() {
runOnUiThread(new Runnable() {
public void run() {
if (adView.isLoaded()) {
adView.show();
}
}
});
}
};
loadAd();
}
@Override
public void onAdClosed() {
loadAd(); // Need to reload the Ad when it is closed.
}
void loadAd() {
AdRequest adRequest = new AdRequest.Builder()
//.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.build();
// Load the adView object witht he request
adView.loadAd(adRequest);
}
//Call displayInterstitial() once you are ready to display the ad.
public void displayInterstitial() {
mHandler.postDelayed(displayAd, 1);
}
}
这篇关于如何创建Android的广告间质性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文