Admob不再显示文字横幅

时间:2014-12-30 14:15:18

标签: java android eclipse admob

在Admob网络界面,我们为我们的应用选择了文字横幅,但未经检查的图片横幅。在我们更新SDK工具,构建工具,平台工具和SDK平台之前,这一直有效。现在,我们的应用会显示我们明确不想获得的仅图片横幅。我们未更改与广告相关的任何代码,也未修改网络界面上的Admob设置。

为了找到问题,我们设置了一个新的测试项目,并逐步完成了关于如何设置Admob的official instructions。同样的问题!以下是生成的代码:

以下是广告(fragment_ad.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_width="match_parent"
    android:layout_height="match_parent">

    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        ads:adSize="BANNER"
        ads:adUnitId="ca-app-pub-XXXXXXXXXXXXXXXX">
    </com.google.android.gms.ads.AdView>

</RelativeLayout>

这是测试活动(MainActivity.java)

package com.example.myadapp;

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;

import android.app.Activity;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    /**
     * A placeholder fragment containing a simple view.
     */
    public static class PlaceholderFragment extends Fragment {

        public PlaceholderFragment() {
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
            View rootView = inflater.inflate(R.layout.fragment_main, container,
                    false);
            return rootView;
        }
    }

    public static class AdFragment extends Fragment {
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState) {
            return inflater.inflate(R.layout.fragment_ad, container, false);
        }

        @Override
        public void onActivityCreated(Bundle bundle) {
            super.onActivityCreated(bundle);
            AdView mAdView = (AdView) getView().findViewById(R.id.adView);
            AdRequest adRequest = new AdRequest.Builder().build();
            mAdView.loadAd(adRequest);
        }
    }
}

...使用布局文件 activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    tools:ignore="MergeRootFrame" >

    <fragment 
        android:id="@+id/placeholder"
        android:name="com.example.myadapp.MainActivity$PlaceholderFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/adFragment" />

    <fragment
        android:id="@+id/adFragment"
        android:name="com.example.myadapp.MainActivity$AdFragment"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true" />
</RelativeLayout>

最后,该应用的 AndroidManifest.xml

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

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

    <uses-sdk
        android:minSdkVersion="19"
        android:targetSdkVersion="19" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        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" >
            <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>

以下是运行GoogleAPIs API19的AVD上的 LogCat

12-31 09:12:26.251: I/Ads(2403): Starting ad request.
12-31 09:12:26.251: I/Ads(2403): Use AdRequest.Builder.addTestDevice("B3EEABB8EE11C2BE770B684D95219ECB") to get test ads on this device.
12-31 09:12:26.411: D/gralloc_goldfish(2403): Emulator without GPU emulation detected.
12-31 09:12:26.751: D/dalvikvm(2403): DexOpt: --- BEGIN 'ads-96486195.jar' (bootstrap=0) ---
12-31 09:12:26.951: D/dalvikvm(2403): DexOpt: --- END 'ads-96486195.jar' (success) ---
12-31 09:12:26.951: D/dalvikvm(2403): DEX prep '/data/data/com.example.myadapp/cache/ads-96486195.jar': unzip in 172ms, rewrite 204ms
12-31 09:12:31.271: D/dalvikvm(2403): GC_FOR_ALLOC freed 262K, 10% free 3566K/3936K, paused 7ms, total 8ms
12-31 09:12:31.271: I/dalvikvm-heap(2403): Grow heap (frag case) to 4.659MB for 1127532-byte allocation
12-31 09:12:31.291: D/dalvikvm(2403): GC_FOR_ALLOC freed 1K, 8% free 4666K/5040K, paused 16ms, total 16ms
12-31 09:12:31.941: I/chromium(2403): [INFO:simple_index_file.cc(397)] Simple Cache Index is being restored from disk.
12-31 09:12:33.091: I/Ads(2403): Scheduling ad refresh 30000 milliseconds from now.
12-31 09:12:33.091: I/Ads(2403): Ad finished loading.

我们按照here所述将 google-play-services-lib 库导入Eclipse。

问题出现在Android 4.0和4.4上,也在模拟器上,无论是否使用com.google.android.gms.ads.AdRequest.Builder.addTestDevice(String deviceId)

将设备添加为测试设备

有人面临同样的问题吗?

编辑:对于测试项目,有时随机显示文字横幅。似乎AdMob并不真正关心在Web界面上进行的自定义......

0 个答案:

没有答案