gpt4 book ai didi

安卓手机

转载 作者:搜寻专家 更新时间:2023-11-01 07:48:07 25 4
gpt4 key购买 nike

我正在尝试将 AdMob 集成到我的应用程序中,并且我已成功检查 AdMob 示例并添加到我的 Android 设备上,但是当我尝试为我的应用程序执行相同的代码但无法正常工作时......请帮助

我的代码

   private void startGame() {
// Request a new ad if one isn't already loaded, hide the button, and kick off the timer.
if (!mInterstitialAd.isLoading() && !mInterstitialAd.isLoaded()) {

runOnUiThread(new Runnable() {
@Override
public void run() {
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("0C3BF98F2CA55F66D0BE2D63D962BF6D")
.build();
mInterstitialAd.loadAd(adRequest);
}
});

}


}
InterstitialAd mInterstitialAd;

void StartAds()
{
MobileAds.initialize(this, "ca-app-pub-3940256099942544~1033173712");
mInterstitialAd = new InterstitialAd(this);
// Defined in res/values/strings.xml
mInterstitialAd.setAdUnitId(getString(R.string.google_home_ad_unit_id));

mInterstitialAd.setAdListener(new AdListener() {
@Override
public void onAdClosed() {

}
});


if (mInterstitialAd != null && mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
} else {

startGame();
}

}

list 文件

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ads.example">

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



<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">

<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version"/>
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</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" />

</application>

</manifest>

渐变

apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "example.ads.app"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.google.firebase:firebase-ads:9.0.0'
}

apply plugin: 'com.google.gms.google-services'

/

/ Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
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
}
}

allprojects {
repositories {
jcenter()
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}

最佳答案

横幅广告

Java 类

AdView mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);

xml

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

//依赖关系

 dependencies{
compile 'com.google.android.gms:play-services:9.2.0'
}

//字符串

 <string name="adUnitID">your add mob UnitID</string>
<string name="interstial_id">your add mob UnitID</string>

// list

     <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" />

插页式广告

Java 类

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
interstitial = new InterstitialAd(INTERSTIAL_ads_Activity.this);
interstitial.setAdUnitId(getResources().getString(R.string.interstial_id);
AdRequest adRequest = new AdRequest.Builder().build();
interstitial.loadAd(adRequest);
interstitial.setAdListener(new AdListener() {
public void onAdLoaded() {
// Call displayInterstitial() function
displayInterstitial();
}
});

private void displayInterstitial(){
if (interstitial.isLoaded()) {
interstitial.show();
}
}

关于安卓手机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39674366/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com