【发布时间】:2016-04-17 18:00:45
【问题描述】:
我正在尝试在我的应用中实现 AdMob,但我对这个 Android 开发还很陌生。 我的要求是,当用户点击一个按钮时,应该会出现一个弹出对话框,该对话框应该在我的文件下载时有一个 AdMob 和一个进度条。
但问题是 AdMob 根本没有加载。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="30dp"
android:minWidth="300dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginTop="10dp">
<com.google.android.gms.ads.AdView
android:id="@+id/bannerAdView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_gravity="center"
android:layout_margin="10dp"
ads:adSize="MEDIUM_RECTANGLE"
ads:adUnitId="@string/ad_banner_unit" />
</LinearLayout>
<ProgressBar
android:id="@+id/download_progress_indicator"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center|bottom"
android:layout_margin="10dp"
android:layout_weight="1" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/cancel_download_action"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center|bottom"
android:layout_margin="20dp"
android:layout_weight="1"
android:src="@drawable/ic_close_black_24dp" />
</LinearLayout>
AdView mAdView = (AdView) view.findViewById(R.id.bannerAdView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
mAdView.setAdListener(new AdListener() {
@Override
public void onAdFailedToLoad(int errorCode) {
Log.d(TAG, "onAdFailedToLoad: " + errorCode);
downloadFile(view);
super.onAdFailedToLoad(errorCode);
}
@Override
public void onAdLoaded() {
Log.d(TAG, "onAdLoaded: loaded");
downloadFile(view);
super.onAdLoaded();
}
});
根据我的代码,只有在广告加载失败或已完成时才会进行下载。
不知何故
Log.d(TAG, "onAdLoaded: loaded");
被击中,但未显示广告。谁能告诉我为什么……我该如何解决……??
【问题讨论】:
-
尝试将 ads:adSize="MEDIUM_RECTANGLE" 更改为 ads:adSize="SMART_BANNER".@Vineet Verma。
标签: android android-fragments admob adsense