不能添加广告到我的应用程序。 [英] Can't add ads to my app.

查看:135
本文介绍了不能添加广告到我的应用程序。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

于是我跟着AdMob提供的本指南与谷歌播放服务, https://developers.google.com/mobile-ads-sdk/docs/admob/fundamentals#play 我曾经遇到过一个问题。 他们提供了在其网站上的code不是working.I出现错误。

So I followed this guide from admob with Google Play Services, https://developers.google.com/mobile-ads-sdk/docs/admob/fundamentals#play And I have encountered a problem. The code they provided on their website is not working.I get errors.

    package puske.com;

import com.google.android.gms.ads.*;
import com.google.ads.AdSize;
import com.google.ads.AdView;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RelativeLayout;

public class Menu extends Activity {
private AdView adView;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.menu);
    // Create the adView.
    adView = new AdView(this);
    adView.setAdUnitId(MY_AD_UNIT_ID);
    adView.setAdSize(AdSize.BANNER);

    // Lookup your LinearLayout assuming it's been given
    // the attribute android:id="@+id/mainLayout".
    RelativeLayout layout = (RelativeLayout)findViewById(R.id.menuz);

    // Add the adView to it.
    layout.addView(adView);

    // Initiate a generic request.
    AdRequest adRequest = new AdRequest.Builder().build();

    // Load the adView with the ad request.
    adView.loadAd(adRequest);

我收到错误的 = AD浏览新的AD浏览报(本); 的构造AD浏览报(菜单)是不确定的。

I get error on adView = new AdView(this); the Constructor AdView(Menu) is undefined.

adView.setAdSize(AdSize.BANNER); the Method setAdSize is undefined for the type AdView

adView.loadAd(adRequest); 在类型AD浏览方法load.ad(adRequest)是不适用的参数(AdRequest)

And adView.loadAd(adRequest); The method load.ad(adRequest) in the type AdView is not applicable for the arguments (AdRequest)

我加 https://developers.google.com/mobile -ads-SDK /文档/?HL = EN_US 在导游说,仍然无法正常工作。 http://prntscr.com/2o6vo4

I added https://developers.google.com/mobile-ads-sdk/docs/?hl=en_US as said in guide, and still doesn't work. http://prntscr.com/2o6vo4

推荐答案

您可以使用布局,以显示你的插件。只要把下面code。在您的布局在任何你想要进入的屏幕。            

You can use layout to show your add. Just put below code in your layout where ever you want into the screen.

     <com.google.ads.AdView
            android:id="@+id/ad"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            ads:adSize="SMART_BANNER"
            ads:adUnitId="Your AddMob ID"
            ads:loadAdOnCreate="true"
            ads:testDevices="TEST_EMULATOR,TEST_DEVICE_ID_GOES_HERE" />  
    </RelativeLayout>

您应该有最新的GoogleAdmobSdk.jar在你libs文件夹。 这是为我工作。

You should have the newest GoogleAdmobSdk.jar in you libs folder. This is working for me.

这篇关于不能添加广告到我的应用程序。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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