伙计们,我在android studio中还算是新手,但是我已经编写了一个已在Google Play商店中上传的应用程序。我的问题是我实现了一个Google admob横幅,如果使用测试ID,它会显示,但是当我将真实ID放在代码中时,它却不会显示。我也有7天的等待时间,并在4台设备上进行了测试。
这是我实现横幅广告的标题和输出的方式。 onCreate方法
MobileAds.initialize(this, "ca-app-pub-2068566232482245~4672139653");
mAdView = 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_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="648dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="8dp"
app:adSize="LARGE_BANNER"
app:adUnitId="ca-app-pub-2068566232482245/9043517552"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.493"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0" />
构建文件
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:27.0.0'
implementation 'com.google.android.gms:play-services-ads:17.2.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
logcat
2019-04-19 22:13:38.962 12794-12887/de.androidnewcomer.quizallgemeinwissen D/libEGL: loaded /vendor/lib64/egl/libGLES_mali.so
2019-04-19 22:13:39.165 12794-12875/de.androidnewcomer.quizallgemeinwissen W/allgemeinwisse: Unsupported class loader
2019-04-19 22:13:39.284 12794-12875/de.androidnewcomer.quizallgemeinwissen W/allgemeinwisse: Skipping duplicate class check due to unsupported classloader
2019-04-19 22:13:39.289 12794-12875/de.androidnewcomer.quizallgemeinwissen I/DynamiteModule: Considering local module com.google.android.gms.ads.dynamite:0 and remote module com.google.android.gms.ads.dynamite:11210
2019-04-19 22:13:39.289 12794-12875/de.androidnewcomer.quizallgemeinwissen I/DynamiteModule: Selected remote version of com.google.android.gms.ads.dynamite, version >= 11210
2019-04-19 22:13:39.365 12794-12875/de.androidnewcomer.quizallgemeinwissen W/allgemeinwisse: Unsupported class loader
2019-04-19 22:13:39.379 12794-12875/de.androidnewcomer.quizallgemeinwissen W/allgemeinwisse: Skipping duplicate class check due to unsupported classloader
2019-04-19 22:13:39.444 12794-12910/de.androidnewcomer.quizallgemeinwissen W/allgemeinwisse: Unsupported class loader
2019-04-19 22:13:39.452 12794-12910/de.androidnewcomer.quizallgemeinwissen W/allgemeinwisse: Skipping duplicate class check due to unsupported classloader
2019-04-19 22:13:39.717 12794-12943/de.androidnewcomer.quizallgemeinwissen I/Ads: App measurement is starting up, version: 14711
2019-04-19 22:13:39.717 12794-12943/de.androidnewcomer.quizallgemeinwissen I/Ads: To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
2019-04-19 22:13:41.348 12794-12794/de.androidnewcomer.quizallgemeinwissen W/ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@c6fa434
2019-04-19 22:13:41.374 12794-12910/de.androidnewcomer.quizallgemeinwissen W/Ads: Got on activity created
2019-04-19 22:13:41.459 12794-12794/de.androidnewcomer.quizallgemeinwissen I/allgemeinwisse: The ClassLoaderContext is a special shared library.
2019-04-19 22:13:41.468 12794-12794/de.androidnewcomer.quizallgemeinwissen I/allgemeinwisse: The ClassLoaderContext is a special shared library.
2019-04-19 22:13:41.531 12794-12794/de.androidnewcomer.quizallgemeinwissen I/DynamiteModule: Considering local module com.google.android.gms.ads.dynamite:0 and remote module com.google.android.gms.ads.dynamite:11210
2019-04-19 22:13:41.532 12794-12794/de.androidnewcomer.quizallgemeinwissen I/DynamiteModule: Selected remote version of com.google.android.gms.ads.dynamite, version >= 11210
2019-04-19 22:13:41.536 12794-12794/de.androidnewcomer.quizallgemeinwissen D/DynamitePackage: Instantiating com.google.android.gms.ads.ChimeraMobileAdsSettingManagerCreatorImpl
2019-04-19 22:13:41.570 12794-12794/de.androidnewcomer.quizallgemeinwissen I/Ads: Updating ad debug logging enablement.
2019-04-19 22:13:41.594 12794-12794/de.androidnewcomer.quizallgemeinwissen I/WebViewFactory: Loading com.android.chrome version 73.0.3683.90 (code 368309052)
2019-04-19 22:13:41.694 12794-12794/de.androidnewcomer.quizallgemeinwissen I/cr_LibraryLoader: Time to load native libraries: 4 ms (timestamps 6897-6901)
2019-04-19 22:13:41.725 12794-12794/de.androidnewcomer.quizallgemeinwissen I/chromium: [INFO:library_loader_hooks.cc(50)] Chromium logging enabled: level = 0, default verbosity = 0
2019-04-19 22:13:41.726 12794-12794/de.androidnewcomer.quizallgemeinwissen I/cr_LibraryLoader: Expected native library version number "73.0.3683.90", actual native library version number "73.0.3683.90"
2019-04-19 22:13:42.025 12794-12794/de.androidnewcomer.quizallgemeinwissen D/DynamitePackage: Instantiating com.google.android.gms.ads.ChimeraAdManagerCreatorImpl
2019-04-19 22:13:42.044 12794-12794/de.androidnewcomer.quizallgemeinwissen I/Ads: Use AdRequest.Builder.addTestDevice("3D3E1F542ADD0C690202584E49A7D658") to get test ads on this device.
2019-04-19 22:13:42.097 12794-13205/de.androidnewcomer.quizallgemeinwissen W/Ads: Invoke Firebase method getInstance error.
2019-04-19 22:13:42.097 12794-13205/de.androidnewcomer.quizallgemeinwissen W/Ads: The Google Mobile Ads SDK will not integrate with Firebase. Admob/Firebase integration requires the latest Firebase SDK jar, but Firebase SDK is either missing or out of date
2019-04-19 22:13:42.105 12794-13151/de.androidnewcomer.quizallgemeinwissen I/allgemeinwisse: The ClassLoaderContext is a special shared library.
2019-04-19 22:13:42.112 12794-13206/de.androidnewcomer.quizallgemeinwissen I/DynamiteModule: Considering local module com.google.android.gms.ads.dynamite:0 and remote module com.google.android.gms.ads.dynamite:11210
2019-04-19 22:13:42.112 12794-13206/de.androidnewcomer.quizallgemeinwissen I/DynamiteModule: Selected remote version of com.google.android.gms.ads.dynamite, version >= 11210
2019-04-19 22:13:42.254 12794-13153/de.androidnewcomer.quizallgemeinwissen W/allgemeinwisse: Accessing hidden field Ljava/nio/Buffer;->address:J (light greylist, reflection)
2019-04-19 22:13:42.273 12794-13151/de.androidnewcomer.quizallgemeinwissen W/Ads: Not retrying to fetch app settings
2019-04-19 22:13:42.360 12794-12794/de.androidnewcomer.quizallgemeinwissen I/Choreographer: Skipped 59 frames! The application may be doing too much work on its main thread.
2019-04-19 22:13:42.434 12794-13152/de.androidnewcomer.quizallgemeinwissen W/Ads: Update ad debug logging enablement as false
2019-04-19 22:13:42.884 12794-12794/de.androidnewcomer.quizallgemeinwissen D/ViewRootImpl@582a837[MainActivity]: Surface release. an
答案 0 :(得分:0)
请尝试在adRequest中添加testDevice,这对我有用。
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.build();
您还可以创建监听器来跟踪广告。
mAdView.setAdListener(new com.google.android.gms.ads.AdListener() {
@Override
public void onAdLoaded() {
super.onAdLoaded();
Log.e("onAdLoaded","AdLoaded");
}
@Override
public void onAdFailedToLoad(int errorCode) {
super.onAdFailedToLoad(errorCode);
Log.e("onAdFailedToLoad",""+errorCode);
}
});
mAdView.loadAd(adRequest);
答案 1 :(得分:0)
您是否在标记应用程序中添加了元数据
<!-- Sample AdMob App ID: ca-app-pub-3940256099942544~3347511713 -->
<application>....
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-3940256099942544~3347511713"/>