Admob 横幅广告在 Android 上无法正常工作

Posted

技术标签:

【中文标题】Admob 横幅广告在 Android 上无法正常工作【英文标题】:Admob banner ads not working properly on Android 【发布时间】:2015-01-10 05:32:06 【问题描述】:

我在点击 ADMOB-BANNER ADS 时在 logcat 中收到消息

无法获取广告重叠式广告的信息

您好,我已经集成了 admob,并遵循它的 xml 代码

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:layout_
    android:layout_ >

    <com.aviary.android.feather.library.services.drag.DragLayer
        android:id="@+id/dragLayer"
        android:layout_
        android:layout_
        android:layout_above="@+id/adView" >

        <RelativeLayout
            android:layout_
            android:layout_
            android:background="?attr/aviaryBackgroundColor"
            android:orientation="vertical" >

            <!-- main navbar ( title, apply and done buttons ) -->

            <include
                android:id="@+id/aviary_navbar"
                layout="@layout/aviary_navbar" >
            </include>

            <!-- main content view -->

            <RelativeLayout
                android:id="@+id/main_content"
                android:layout_
                android:layout_
                android:layout_above="@+id/aviary_bottombar"
                android:layout_below="@id/aviary_navbar"
                android:padding="?attr/aviaryMainImagePadding" >

                <!-- optional image view container -->

                <RelativeLayout
                    android:id="@+id/drawing_view_container"
                    android:layout_
                    android:layout_ >
                </RelativeLayout>

                <!-- main image view -->

                <com.aviary.android.feather.sdk.widget.AviaryImageViewUndoRedo
                    android:id="@+id/image"
                    android:layout_
                    android:layout_
                    android:visibility="invisible" />

                <!-- main loader, visible while loading the image at start -->

                <include
                    android:id="@+id/image_loading_view"
                    layout="@layout/aviary_main_loader" >
                </include>
            </RelativeLayout>

            <!-- bottom bar (tools, panels) -->

            <include
                android:id="@+id/aviary_bottombar"
                android:layout_
                android:layout_
                android:layout_alignParentBottom="true"
                layout="@layout/aviary_bottombar" >
            </include>

            <!-- popup container dialog -->

            <RelativeLayout
                android:id="@+id/feather_dialogs_container"
                android:layout_
                android:layout_
                android:layout_below="@+id/aviary_navbar"
                android:visibility="invisible" >
            </RelativeLayout>

            <!-- hidden surface view -->

            <SurfaceView
                android:layout_
                android:layout_
                android:visibility="invisible" >
            </SurfaceView>
        </RelativeLayout>
    </com.aviary.android.feather.library.services.drag.DragLayer>

    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_
        android:layout_
        android:layout_alignParentBottom="true"
        ads:adSize="SMART_BANNER"
        ads:adUnitId="@string/banner_ad_unit_id" >
    </com.google.android.gms.ads.AdView>

</RelativeLayout>

这是Java代码

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

这是清单文件

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

但是每当我点击横幅广告时,它都会显示点击响应,但不会转移到游戏商店或浏览器

【问题讨论】:

【参考方案1】:

activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:layout_
    android:layout_ >

    <TextView
        android:layout_
        android:layout_
        android:text="@string/hello_world" />

    <!-- Creating AdView in XML and loading an ad -->

    <com.google.android.gms.ads.AdView
        android:layout_alignParentBottom="true"
        android:id="@+id/adView"
        android:layout_
        android:layout_
        ads:adSize="BANNER"
        ads:adUnitId="(Here paste your google add key)" />

</RelativeLayout>

MainActivity.java

public class MainActivity extends Activity 

    @Override
    public void onCreate(Bundle savedInstanceState) 
        super.onCreate(savedInstanceState);
        // Get the view from activity_main.xml
        setContentView(R.layout.activity_main);

        AdView mAdView = (AdView) this.findViewById(R.id.adView);
        AdRequest adRequest = new AdRequest.Builder()
        // Add a test device to show Test Ads
        .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
               .build();
        mAdView.loadAd(adRequest);
    

AndroidManifest.xml

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

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.test.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <!-- Include the AdActivity configChanges and theme. -->
    <activity
        android:name="com.google.android.gms.ads.AdActivity"
        android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
        android:theme="@android:style/Theme.Translucent" />
    <!-- Google Play Service Meta-data Info -->
    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />
</application>

【讨论】:

以上是关于Admob 横幅广告在 Android 上无法正常工作的主要内容,如果未能解决你的问题,请参考以下文章

无法显示 AdMob 横幅

Admob广告请求始终返回代码3

AdMob横幅未在设备上显示

iOS 和 Android:在不更新整个应用程序的情况下摆脱 Admob 横幅广告的最快方法?

广告服务器无法填充。广告:无法加载广告:3

为啥谷歌 Admob 广告不显示