Android Studio Add AdMob googgle Play Services
Import Com.google.android.gms.ads.AdRequest;
Import Com.google.android.gms.ads.AdListener;
Import Com.google.android.gms.ads.InterstitialAd;
Import Com.google.android.gms.ads.MobileAds;
Private Interstitialad Minterstitialad;
//Initialize the Mobile Ads SDK.
Mobileads.initialize (Getapplicationcontext (), "ca-app-pub-8067415904846806/59920985");
//Create the Interstitialad and set the Adunitid.
Minterstitialad = new Interstitialad (this);
//Defined in Res/values/strings.xml
Minterstitialad.setadunitid ("xxx");
Minterstitialad.setadlistener (New Adlistener () {
@Override
public void onadclosed () {
//s Tartgame ();
}
@Override
public void onadloaded () {
super.onadloaded ();
LOG.I ("SDF", "Ad loaded!");
}
});
Adrequest adrequest = new Adrequest.builder (). Addtestdevice ("0e1f15f35ce93f7a77bddb59f7fe29af"). Build ();
Minterstitialad.loadad (adrequest);
Androidmanifest.xml
<!--used to request banner and interstitial ads. -
<uses-permission android:name= "Android.permission.INTERNET"/>
<!--used to avoid sending a ad request if there is no connectivity. -
<uses-permission android:name= "Android.permission.ACCESS_NETWORK_STATE"/>
<!--Required permissions for video ads. -
<uses-permission android:name= "Android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name= "Com.google.android.gms.permission.ACTIVITY_RECOGNITION"/>
<uses-permission android:name= "Android.permission.READ_CALENDAR"/>
<uses-permission android:name= "Android.permission.WRITE_CALENDAR"/>
<meta-data
Android:name= "com.google.android.gms.version"
android:value= "@integer/google_play_ Services_version "/>
<activity android:name=" com.google.android.gms.ads.AdActivity "
Android: Configchanges= "Keyboard|keyboardhidden|orientation|screenlayout|uimode|screensize|smallestscreensize"
Android:theme= "@android: Style/theme.translucent"/>
App Build.gradle
dependencies {
Compile Filetree (dir: ' Libs ', include: [' *.jar '])
Androidtestcompile (' com.android.support.test.espresso:espresso-core:2.2.2 ', {
Exclude group: ' Com.android.support ', module: ' Support-annotations '
})
Compile ' com.android.support:appcompat-v7:25.3.1 '
Testcompile ' junit:junit:4.12 '
Compile ' com.android.support.constraint:constraint-layout:1.0.2 '
Compile ' com.android.support:design:25.3.1 '
Compile ' com.google.android.gms:play-services-ads:10.2.0 '
Compile ' com.android.support:multidex:1.0.1 '
}
Apply plugin: ' Com.google.gms.google-services '
Project Build.gradle
dependencies {
Classpath ' Com.android.tools.build:gradle:2.4.0-alpha6 '
Classpath ' com.google.gms:google-services:3.0.0 '
Note:do not place your application dependencies here; They belong
In the individual module Build.gradle files
}
Android Studio Add AdMob googgle Play Services