Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Interstitial ads not showing

I'm trying to add ads on my APP, the problem is that I've followed the Getting Started in AdMob for Android, and the ads aren't being shown up.

I've added on my manifest.xml the following:

<meta-data android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />

And I've added two permissions as follows:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

Then, I've added an Activity also:

<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="@android:style/Theme.Translucent" />

I want the INTERSTITIAL AD; As far as I know, there are the ads that fill the screen... So, I tried this:

On my MainActivity.java I've added the following:

mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId(getString(R.string.banner_ad_unit_id));
mInterstitialAd.setAdListener(new AdListener() {
        @Override
        public void onAdClosed() {
            requestNewInterstitial();

        }
});

On my activity_main.xml I've added the following:

<com.google.android.gms.ads.AdView
    android:id="@+id/Home"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_alignParentBottom="true"
    ads:adSize="BANNER"
    ads:adUnitId="@string/banner_ad_unit_id">
</com.google.android.gms.ads.AdView>

However, the ad is being never shown... When I see the LogCat I can't see any error... So, what I'm missing?

I don't want the banner; I want the full-screen ads. Shen I created the AD-Mob publisher-ID, I put 7 seconds; however, it isn't appeared...

EDIT

I've get something... I've read some tutorials and I think I've found the way to do it... here's my code now :

MainActivity.java

end_ad=new InterstitialAd(this);
end_ad.setAdUnitId(getResources().getString(R.string.banner_ad_unit_id));
end_ad.loadAd(new AdRequest.Builder().build());

And on my Activity on an onClickListener() I've added this code :

if(end_ad.isLoaded()){
    end_ad.show();
    Log.d(TAG,"SHOWING");
}
else{
    Log.d(TAG, "NOT SHOWING");
}

But only it's shown once... Any idea why?

like image 979
Skizo-ozᴉʞS Avatar asked Aug 18 '15 14:08

Skizo-ozᴉʞS


People also ask

How do I show interstitial ads?

Interstitial ads should be displayed during natural pauses in the flow of an app. Between levels of a game is a good example, or after the user completes a task. To show an interstitial, use the show() method.

Where do interstitial ads go?

In between page content, levels, or stages Avoid placing an interstitial ad every single time the user does an action. It is recommended that interstitial ads appear before the break page rather than after. Break pages often require a user to tap a Next button (or equivalent).

Why ads are not showing on my app?

Have you integrated the Google Mobile Ads SDK correctly? Take a look at the sample apps available for Android and iOS. Sample apps show how to use the Google Mobile Ads SDK to place ads into apps. Ads won't show if you haven't integrated the Google Mobile Ads SDK correctly.


1 Answers

I've solved it doing ...

Creating a InterstitialAd

private InterstitialAd end_ad;

Inside on onCreate() initializing it as follows :

//ADS
    end_ad=new InterstitialAd(this);
    end_ad.setAdUnitId(getString(R.string.banner_ad_unit_id);
    end_ad.loadAd(new AdRequest.Builder().build());

Then I've created a method called displayInterstitial that looks like :

 public void displayInterstitial() {
    // If Ads are loaded, show Interstitial(end_ad) else show nothing.
    if (end_ad.isLoaded()) {
        end_ad.show();
    }
}

Then on every onClickListener() I call this method to show ads, it will only show once unless you make a finish() on current Activity or remove from recents.

like image 197
Skizo-ozᴉʞS Avatar answered Oct 20 '22 19:10

Skizo-ozᴉʞS