安卓 AdSense。在应用程序中看不到广告

发布于 2024-11-15 08:26:48 字数 1041 浏览 5 评论 0原文

我在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

金兰素衣 2024-11-22 08:26:49

如果您通过 xml/layout 文件 设置 adView,请按照以下指示操作:-

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

<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() 方法onCreate() 方法 中写入此代码代码>活动生命周期:-

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

现在如果你想编程在您的 Activity 中设置 AdView,然后按照以下步骤操作:-

在您的 onCreate() 方法 中编写以下代码,
我正在演示 Fragment,因此请在 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());

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

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

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"
        />

And in your Activity.java file write this code in your onCreate() Method of the Activity Life Cycle:-

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

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 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...

凉风有信 2024-11-22 08:26:48

将新的 AdView 声明更改为:

adView =  new AdView(this, AdSize.BANNER, "a14def820df0417");

引擎对象不包含其维度的上下文。表行的维度位于活动上下文“this”中

Change the new AdView declaration to:

adView =  new AdView(this, AdSize.BANNER, "a14def820df0417");

The engine object does not contain the context for its dimensions. The dimensions of the table row are in the Activity context "this"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文