Implement google admob interstitial ads in aide ide


Tutorial on how to integrate google admob interstitial ads in aide ide. Interstitial ads are full-screen ads that cover the interface of their host app. They're typically displayed at natural transition points in the flow of an app, such as between activities or during the pause between levels in a game. When an app shows an interstitial ad, the user has the choice to either tap on the ad and continue to its destination or close it and return to the app.

Before start coding you need admob account or use the test ads account to test your admob codes integration.

Now lets start for coding, first goto your "build.gradle" and add this code:
compile 'com.google.android.gms:play-services-ads:+'
or click the "Add to project" » select "com.google.android.gms:play-services-ads:+"

Next goto your "AndroidManifest.xml" and add this following codes:
Permission:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

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

Activity:
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="@android:style/Theme.Translucent" />
AndroidManifest.xml screenshot:
Integrate google admob interstitial ads aide ide


Next goto your java files, example "MainActivity.java" and add this following codes below.
//code 1
import android.util.*;
import com.google.android.gms.ads.MobileAds;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.InterstitialAd;
import com.google.android.gms.ads.AdListener;

private InterstitialAd mInterstitialAd;
MobileAds.initialize(getApplicationContext(), "ca-app-pub-3940256099942544/1033173712");
mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);

mAdView.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
Log.i("Ads", "onAdLoaded");
}
@Override
public void onAdFailedToLoad(int errorCode) {
Log.i("Ads", "onAdFailedToLoad");
}
@Override
public void onAdOpened() {
Log.i("Ads", "onAdOpened");
}
@Override
public void onAdLeftApplication() {
}
@Override
public void onAdClosed() {
Log.i("Ads", "onAdClosed");
}
});

Don't forgot to change the "ca-app-pub-3940256099942544/1033173712" to your cap-app-pub, when you test your ads make sure use the test ads unit.


Here the codes that call interstitial ads to show in your activity, you can put this inside the button function or oncreate.
///Intertital will show if button is click
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
} else {
Log.d("TAG", "The interstitial wasn't loaded yet.");
}

Screenshot:


Done.
I recommend to read this documentation from official website here https://developers.google.com/admob/android/quick-start  and also visit this google admob banner tutorials


Comments

Popular posts from this blog

Implement in-app purchase in aide ide

Android listview with search function using aide ide

Implement google admob banner ads in aide ide

Aide ide tutorial - Add line graph


Malitanyo Developer blog & tutorial 2020
Refund Policy    Facebook Page    Google Play

Blogger.com