所以我有一个项目(模块真的因为我使用IntelliJ,但我会使用Eclipse术语)和Activity(让我们称之为X)加载一个AdView并且它都有效正好。现在我有另一个Activity(让我们称之为Y),它在某些动作之后打开,该Activity在一个库项目中。活动Y打开很好,效果很好,但我添加的AdView从来没有任何内容,它只是空白。以下是我在日志中看到的一些奇怪的消息:
I/Ads﹕ Starting ad request.
I/webclipboard﹕ clipservice: android.sec.clipboard.ClipboardExManager@4293f940
W/ResourceType﹕ Requesting resource 0x7f0b000e failed because it is complex
E/GooglePlayServicesUtil﹕ The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
I/Adreno200-EGLSUB﹕ <ConfigWindowMatch:2087>: Format RGBA_8888.
onSizeChanged - w:640 h:100
W/ResourceType﹕ Requesting resource 0x7f0b000e failed because it is complex
E/GooglePlayServicesUtil﹕ The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
W/ResourceType﹕ Requesting resource 0x7f0b000e failed because it is complex
E/GooglePlayServicesUtil﹕ The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
这两条消息稍后发生,经过一段时间(接近60秒):
W/Ads﹕ Timed out waiting for WebView to finish loading.
I/Ads﹕ Scheduling ad refresh 60000 milliseconds from now.
W/Ads﹕ Failed to load ad: 2
以下是我用来创建AdView的代码:
adView = new AdView(this);
adView.setAdSize(AdSize.BANNER);
adView.setAdUnitId(id);
buttonsAndSeekbarLayout.addView(adView);
final AdRequest.Builder builder = new AdRequest.Builder();
AdRequest adRequest = builder.build();
// Start loading the ad in the background.
adView.loadAd(adRequest);
我还应该提一下,我在该图书馆项目中使用Google Play服务的其他部分,因此我认为它配置正确。
感谢。
编辑:我应该提一下,即使我在xml上添加了adView,它仍然只是空白!
EDIT2:在上面添加了一些额外的消息。此外,我注意到这条消息在进行搜索后似乎与AdView相关:
D/WebKit﹕ SQLite database failed to load from /FileSyetmQuota.db
编辑3:我发现了一些奇怪的东西。我在应用购买中添加了购买完成后,在我删除广告之前(因为购买),它显示了一秒钟的分割。
答案 0 :(得分:0)
E/GooglePlayServicesUtil﹕ The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
。忽略该消息,即使您正确运行GP服务也会出现,但这不是问题。
您创建AdView
并加载广告的代码部分非常完美,这不是问题(我在几个项目中运行完全相同的代码并且它可以正常工作)。
考虑到上述情况,我的赌注只有两个:
不知何故,图书馆项目正在干扰广告的加载。广告加载有一段时间,如果您正在做一些艰苦的工作,可能没有足够的时间加载广告并且超时,所以可能就是您看到的原因Timed out waiting for WebView to finish loading.
消息。在这种情况下,请尝试将广告加载设置为Thread
(或AsyncTask
)。
布局呈现问题。您必须检查广告是否有足够的空间显示,即最小宽度为640 x高度为100。如果您没有这个空间,广告就不会出现。
----编辑----
要在Thread
内运行代码,请使用以下代码:
new Thread(
new Runnable() {
@Override
public void run() {
adView = new AdView(this);
adView.setAdSize(AdSize.BANNER);
adView.setAdUnitId(id);
// This will ensure it is run within the main UI.
runOnUiThread(new Runnable() {
public void run() {
buttonsAndSeekbarLayout.addView(adView);
}
});
final AdRequest.Builder builder = new AdRequest.Builder();
AdRequest adRequest = builder.build();
// Start loading the ad in the background.
adView.loadAd(adRequest);
}
}
}).start();
答案 1 :(得分:0)
嘿,请尝试加载广告,如下面的示例
首先将您的Google Play lib更新为4.3
合并广告的最简单方法是简单地定义AdView,就像调整res / layout / 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/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.gms.ads.AdView android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="MY_AD_UNIT_ID"
ads:adSize="BANNER"/>
</LinearLayout>
您必须将MY_AD_UNIT_ID替换为您的AdMob广告单元ID。
要获取广告,请通过findViewById将AdView作为资源查找,创建AdRequest,然后调用loadAd:
import com.google.android.gms.ads.*;
public class BannerExample extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Look up the AdView as a resource and load a request.
AdView adView = (AdView)this.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
}
}
答案 2 :(得分:0)
想出来,在我的代码中我调用了webViewInstance.pauseTimers()
,显然这适用于所有网络视图。