3

我尝试在我的应用程序中使用 Admob,并尝试了以下操作。你能告诉我为什么我会收到这个错误吗?

活动.main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
              android:orientation="vertical"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent">
    <TextView android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:text="@string/hello"/>
    <com.google.ads.AdView android:id="@+id/ad"
                           android:layout_width="wrap_content"
                           android:layout_height="wrap_content"
                           ads:adSize="BANNER"
                           ads:adUnitId="/6253334/dfp_example_ad"
                           ads:testDevices="TEST_EMULATOR,DB5C6285034D8192153E5D66D726E418"
                           ads:loadAdOnCreate="true"/>
</LinearLayout>

MainActivity.java

package test.admobtest;

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

import android.os.Bundle;
import android.os.Looper;
import android.app.Activity;

public class MainActivity extends Activity {

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

        final AdView adView = (AdView)this.findViewById(R.id.ad);
        new Thread(){
            public void run() {
                Looper.prepare();
                AdRequest re = new AdRequest();
                re.setTesting(true);
                adView.loadAd(re);
            };
        }.start();      

    }

}

AndroidManifest.xml:

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

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />
      <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.INTERNET"/>

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="test.admobtest.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.ads.AdActivity"
                  android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
    </application>

</manifest>

日志:

07-08 10:34:34.589: I/webclipboard(26978): clipservice: android.sec.clipboard.ClipboardExManager@4052f5d0
07-08 10:34:34.849: I/webclipboard(26978): clipservice: android.sec.clipboard.ClipboardExManager@4052f5d0
07-08 10:34:34.909: E/ActivityThread(26978): Failed to find provider info for com.google.plus.platform
07-08 10:34:34.929: W/Ads(26978): loadAd called while the ad is already loading, so aborting.
07-08 10:34:34.979: I/Ads(26978): adRequestUrlHtml: <html><head><script src="http://media.admob.com/sdk-core-v40.js"></script><script>AFMA_getSdkConstants();AFMA_buildAdURL({"preqs":1,"session_id":"10000751322559007096","seq_num":"2","slotname":"\/6253334\/dfp_example_ad","u_w":320,"msid":"test.admobtest","adtest":"on","js":"afma-sdk-a-v6.4.1","bas_off":0,"net":"wi","app_name":"1.android.test.admobtest","hl":"en","gnt":3,"carrier":"40440","u_audio":3,"kw":[],"u_sd":1,"ms":"n54ldDZ15bdyTg9xXgxtdXMgomxIrXGdOYvqk2l8bUwTFSRmnmpAVljV0IHyknLTNWRCdF8oj52F_2JERnz-3C-DJsIQ9wGFBnH88tqEb9BjAtNZ3-ni5am3uWBAyUygwgpiyTTzY6cgUeA4g_QnU5Qrh3savu2bMY_3nsjuW9fH7W7x-5HC_oDuaVe6U05Pypm5FMyWGYFqBd0-s6_p_IFm0AhPOYvujrNtCxqC4inyELVT2E0laAKwjvaWVqA5yzjILYNspqByel6t3TMiiZ3z3k7Qc9HYIRsHwRV3cbdtSb_pk5eZCgjTZhaippVWsXwUC-eoMxMdBtfqUHqA9w","mv":"80210006.com.android.vending","isu":"DB5C6285034D8192153E5D66D726E418","format":"320x50_mb","oar":0,"ad_pos":{"height":0,"visible":0,"y":0,"x":0,"width":0},"u_h":480,"pt":1,"bas_on":0,"ptime":20956});</script></head><body></body></html>
07-08 10:34:34.999: W/webcore(26978): Can't get the viewWidth after the first layout
4

3 回答 3

1

我已经尝试了以下并正在工作

使用 Admob - 放置 jar 文件并设置路径:

  1. 从 Google 网站下载 AdMob SDK(可能是不同的链接取决于国家/地区)https://developers.google.com/mobile-ads-sdk/download?hl=de

  2. 将文件解压缩到一个目录中(无论在哪里)

  3. 在 Eclispe 的项目中创建一个“libs”文件夹。确保文件夹被命名为“libs”而不是“lib”。这个错误经常发生

  4. 将 jar 文件从 admob 文件夹复制到您的项目到 libs 文件夹中,在 lib 文件夹内的 jar 文件上单击鼠标右键,然后选择 Build Path-->add to build path

  5. 要确保一切都已真正完成,请在您的项目上单击鼠标右键并选择属性
  6. 选择 Java-Build-Path 并转到库选项卡
  7. 选择添加外部 jar 并从您的 admob 文件夹中选择此 jar
  8. 选择确定

添加admob后,来自 Android应用程序的引用无法启动

于 2013-07-08T07:13:47.460 回答
0

试着放

adview.loadAd(new AdRequest())

在 UI 线程中希望它会帮助你。

于 2013-07-08T07:02:15.453 回答
0

也可能是因为用户没有登录 Gplus 或没有安装 G+ 或 Google Play 服务?

我在日志中收到此消息,但广告运行良好。

于 2013-11-13T07:24:15.893 回答