安卓 AdSense。在应用程序中看不到广告
我在使用 AdSence 时遇到问题。过去几天我试图解决这个问题,但没有任何好的结果。我使用了开发人员指南,但横幅位置仍然是空的。
我在应用程序中做什么。首先,我添加了一个 TableRow 对象并向其中添加了 AdView:
banner = new TableRow(engine);
banner.setGravity(Gravity.TOP & Gravity.RIGHT);
adView = new AdView(engine, AdSize.BANNER, "a14def8xxxxxxxx");
banner.addView(adView);
AdRequest request = new AdRequest();
adView.loadAd(request);
之后我只是将这个“横幅”对象添加到另一个视图中。最后 - 那里没有输出。如果我将 AdView 更改为 TextView,只是为了概念证明,它工作得很好。
输出日志:
06-13 18:04:38.476: INFO/Ads(576): 收到广告网址:<"url": "http://r.admob.com:80/ad_source.php?... > 06-13 18:04:40.406: INFO/Ads(576): onReceiveAd()
日志中对我来说唯一奇怪的是:
06-13 18:04:40.336: WARN/webcore(576): 无法获取第一个布局后的 viewWidth
我还没有找到它是什么意思,是否是因为 AdSence。
更新
我有类:
public class QuestEngine extends Activity {
然后我尝试在方法中生成新的 AdView:
public IntroView(QuestEngine engine) {
这就是为什么在“新 AdView”中我使用引擎对象。
I have a problem with AdSence. I have tried to resolve it the last couple of days but without any good results. I used developers guide but it still empty on the place of banner.
What am I doing in an application. First of all I have added a TableRow object and added AdView to it:
banner = new TableRow(engine);
banner.setGravity(Gravity.TOP & Gravity.RIGHT);
adView = new AdView(engine, AdSize.BANNER, "a14def8xxxxxxxx");
banner.addView(adView);
AdRequest request = new AdRequest();
adView.loadAd(request);
Afterwards I just added this "banner" object to the other view. At the end - there is no output there. In case I changed AdView to TextView, just for the proof of concept, it works fine.
The output log:
06-13 18:04:38.476: INFO/Ads(576): Received ad url: <"url": "http://r.admob.com:80/ad_source.php?... >
06-13 18:04:40.406: INFO/Ads(576): onReceiveAd()
The only strange thing for me in log is:
06-13 18:04:40.336: WARN/webcore(576): Can't get the viewWidth after the first layout
I haven't found what is it means and is it because of AdSence.
Update
I have the class:
public class QuestEngine extends Activity {
Then I am trying to produce new AdView in method:
public IntroView(QuestEngine engine) {
That is why in "new AdView" I am using engine object.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您通过
xml/layout 文件
设置adView
,请按照以下指示操作:-在您的
activity.xml
文件中插入以下标记您希望显示AdView
的位置:-在您的
Activity.java
文件中,在onCreate() 方法
的onCreate() 方法
中写入此代码代码>活动生命周期:-现在如果你想编程在您的 Activity 中设置
AdView
,然后按照以下步骤操作:-在您的
onCreate() 方法
中编写以下代码,我正在演示
Fragment
,因此请在onActivityCreated()Method
中编写以下代码。希望这可以帮助任何未来的用户......
Well if you are setting your
adView
viaxml/layout file
then do as directed below:-In your
activity.xml
file insert the following tag where you want yourAdView
to be shown:-And in your
Activity.java
file write this code in youronCreate() Method
of theActivity Life Cycle
:-Now if you want to programmatic set the
AdView
in your Activity then follow the steps as directed below:-Write the following code in your
onCreate() method
,I am demonstrating for
Fragment
, so write the following code in youronActivityCreated()Method
.Hope This can help Any Future users...
将新的 AdView 声明更改为:
引擎对象不包含其维度的上下文。表行的维度位于活动上下文“this”中
Change the new AdView declaration to:
The engine object does not contain the context for its dimensions. The dimensions of the table row are in the Activity context "this"