Android版的AdSense。无法看到广告中的应用 [英] Android AdSense. Can't see an advertisement in an application

查看:204
本文介绍了Android版的AdSense。无法看到广告中的应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有AdSence问题。我试图解决它在过去几天,但没有什么好结果。我用的开发者指南,但它仍然空横幅的地方。

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.

我是什么在应用程序中做什么。首先,我添加了一个对象的TableRow并添加AdView中的:

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);

后来我只是说这个旗帜对象到其他视图。在结束 - 没有输出存在。如果我改变AdView中TextView的,只是概念的证明,它工作正常。

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.

输出日志:

18 06-13:04:38.476:信息/广告(576):接收到广告网址:其中,URL:HTTP://r.admob.com:80 / ad_source.php ...>
06-13 18:04:40.406:信息/广告(576):onReceiveAd()

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:

18 06-13:04:将40.336:WARN / WebCore的(576):第一个布局后无法获得viewWidth

06-13 18:04:40.336: WARN/webcore(576): Can't get the viewWidth after the first layout

我还没有发现它是什么意思,是不是因为AdSence的。

I haven't found what is it means and is it because of AdSence.

更新

我有类:

public class QuestEngine extends Activity {

然后我试图产生方法新的AdView:

Then I am trying to produce new AdView in method:

public IntroView(QuestEngine engine) {

这就是为什么在新的AdView我使用的引擎对象。

That is why in "new AdView" I am using engine object.

推荐答案

好吧,如果你设置你的的AdView 通过 XML /布局文件那么就按照指示如下: -

Well if you are setting your adView via xml/layout file then do as directed below:-

在你的 activity.xml 文件中插入您希望以下标记你的的AdView 来显示: -

In your activity.xml file insert the following tag where you want your AdView to be shown:-

<com.google.ads.doubleclick.DfpAdView 
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ads:adUnitId="/XXXXX/XXXXX"
        ads:adSize="BANNER"
        />

而在你的 Activity.java 文件写在 onCreate()方法这个code 活动生命周期: -

// Look up the DfpAdView as a resource and load a request.
        adView = (DfpAdView)this.findViewById(R.id.adView);
        adView.loadAd(new AdRequest()); 

现在,如果你想编程设置的AdView 在你的活动然后按照步骤如下指示: -

Now if you want to programmatic set the AdView in your Activity then follow the steps as directed below:-

写在 onCreate()方法如下code
我演示了片段,所以写在 onActivityCreated()方法以下code

Write the following code in your onCreate() method, I am demonstrating for Fragment, so write the following code in your onActivityCreated()Method.

// Create an ad view as a second header for now to meet deadlines
        DfpAdView mAdView=null; //you can also define this as a Global Variable.
        if (mAdView == null) {
            mAdView = new DfpAdView(getActivity(), AdSize.BANNER, "/XXXX/XXXX"); //give your adId incase of XXXX
            iaddHeight= (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 50, getResources().getDisplayMetrics()); //This code is used to set the height of the addHeight as 50 pixels, which could be used in layout params.

            RelativeLayout fl =new RelativeLayout(this.getActivity());
            RelativeLayout.LayoutParams flParams =new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, 
                    LayoutParams.WRAP_CONTENT);
            flParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);

            FrameLayout.LayoutParams para =new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, 
                    LayoutParams.MATCH_PARENT); 
         para.setMargins(0, 0, 0,iaddHeight);

        getListView().setLayoutParams(para);

        this.getActivity().addContentView(fl, flParams);        
        fl.addView(mAdView,flParams);
        }
        mAdView.loadAd(new AdRequest());

希望这可以帮助任何未来的用户...

Hope This can help Any Future users...

这篇关于Android版的AdSense。无法看到广告中的应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆