I integrate the interstitial ad from admob in my application and that is of google play version. I want to show ad on starting of app but it does not work. I have a code in which ad comes up on "onPause", "onResume" etc methods. Is there any way to show ad on starting of app like within 2 second of starting an app. Here is my code for interstitial.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
StartAppAd.init(this, "110342272", "204516610");
setContentView(R.layout.activity_start);
// Create the interstitial.
interstitial = new InterstitialAd(this);
interstitial.setAdUnitId("ca-app-pub-2869508995487312/2690564381");
// Create ad request.
AdRequest adRequest = new AdRequest.Builder().build();
// Begin loading your interstitial.
interstitial.loadAd(adRequest);
}
@Override
protected void onPause() {
display();
super.onStart();
}
public void display() {
if (interstitial.isLoaded()) {
interstitial.show();
}
}
According to new policies of Admob , interstitial ads are not permitted on start and exiting of app.Your account may be banned if you will violate this policy. Therefore avoid it. Please click on the following link to read the admob policy for more clarification. https://support.google.com/admob/answer/6201362?hl=en
Here's what I created to load interstitial ad when user open the app:
InterstitialAd interstitial;
private static final String AD_UNIT_ID = "YOUR_AD_UNIT_ID";
private InterstitialAd interstitialAd;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_start);
interstitialAd = new InterstitialAd(this);
interstitialAd.setAdUnitId(AD_UNIT_ID);
AdRequest adRequest = new AdRequest.Builder().build();
interstitialAd.loadAd(adRequest);
interstitialAd.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
if (interstitialAd.isLoaded()) {
interstitialAd.show();
}
}
@Override
public void onAdOpened() {
}
@Override
public void onAdFailedToLoad(int errorCode) {
}
});
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With