Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

want to show admob interstitial on app start

Tags:

android

admob

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();
}
}
like image 247
user3217774 Avatar asked Nov 28 '22 01:11

user3217774


2 Answers

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

like image 111
Ovais Chaudhry Avatar answered Nov 30 '22 14:11

Ovais Chaudhry


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) {

        }
    });

}
like image 37
Sestertius Avatar answered Nov 30 '22 15:11

Sestertius