我尝试在我的应用程序中使用Admob,并尝试了以下方法。你能不能告诉我为什么我会收到这个错误?
activity.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
答案 0 :(得分:1)
我已经尝试了以下内容并立即开始工作
使用Admob - 放置jar文件并设置路径:
从Google网站下载AdMob SDK(可能是不同的链接,具体取决于国家/地区)https://developers.google.com/mobile-ads-sdk/download?hl=de
将文件解压缩到一个目录中(无论在哪里)
在Eclispe的项目中创建一个“libs”文件夹。请确保文件夹被命名为“libs”而不是“lib”。这个错误已经完成了
将jar文件从admob文件夹复制到您的项目中的libs文件夹中 在lib文件夹内的jar文件上单击鼠标右键,然后选择Build Path - &gt; add to build path
答案 1 :(得分:0)
尝试放
adview.loadAd(new AdRequest())
UI线程中的希望它能帮到你。
答案 2 :(得分:0)
也可能是因为用户没有登录Gplus或者没有打扰安装G +或Google Play服务?
我在日志中收到此消息,但广告正常运行。