Android Studio Add AdMob googgle Play Services

Source: Internet
Author: User
Tags admob

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.