zoukankan      html  css  js  c++  java
  • Android studio 添加admob googgle play services

    Android studio 添加admob googgle play services

     MainActivity 
    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() {
    // startGame();
    }
    @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 an 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
    }


  • 相关阅读:
    centos下修改ip
    在sql2008的实例 中 编写存储过程 读取 版本为sql2005 的实例 中的某个数据库里的数据
    解决javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure报错
    Micronaut事务管理
    [make] 第二章 makefile 总述
    [make] 第一章 make 介绍
    [other] AutoHotKey.ahk
    2021年11月国产数据库大事记墨天轮
    风云再起之国产数据库风云榜2021年12月
    2021年12月墨天轮国产数据库排行榜: openGauss节节攀升拿下榜眼,GaussDB与TDSQL你争我夺各进一位
  • 原文地址:https://www.cnblogs.com/zzxap/p/6797452.html
Copyright © 2011-2022 走看看