admob 横幅未显示

发布于 2024-12-15 00:15:53 字数 2775 浏览 2 评论 0原文

我知道这已经讨论过很多次了,但我无法做到这一点:(。我真的尝试过,但我没有成功。

我已将 GoogleAdMobAdsSdk-4.0.4.jar 添加到我的 libs 文件夹中,然后添加 我

我还应该做什么?我没有看到我的横幅,它永远不会显示

想我做了一些非常愚蠢的事情,但我无法意识到

这是我的活动

package com.google.ads.example;

import com.google.ads.AdRequest;
import com.google.ads.AdSize;
import com.google.ads.AdView;

import android.app.Activity;
import android.os.Bundle;
import android.widget.LinearLayout;

public class BannerEssentials extends Activity{
  private static final String MY_BANNER_UNIT_ID = "123";

@Override
  public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // Lookup R.layout.main
    LinearLayout layout = (LinearLayout)findViewById(R.id.linearLayout);

    // Create the adView
    // Please replace MY_BANNER_UNIT_ID with your AdMob Publisher ID
    AdView adView = new AdView(this, AdSize.BANNER, MY_BANNER_UNIT_ID);

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

    // Initiate a generic request to load it with an ad
    AdRequest request = new AdRequest();
    request.setTesting(true);

    adView.loadAd(request);            
  }
}

这是我的清单

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.google.ads.example"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".BannerEssentials"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="com.google.ads.AdActivity" 
              android:configChanges="keyboard|keyboardHidden|orientation"/>
    </application>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> 
    <uses-sdk android:minSdkVersion="3" />

</manifest> 

这是我的布局 main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/linearLayout"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello"
    />
</LinearLayout>

I know this have been discussed many times but I couldn't menage to make this work :(. I really tried but I didn't make it.

I have add the GoogleAdMobAdsSdk-4.0.4.jar to my libs folder and I add it to build path.

What else should I do ? I do not see my banner, it never get shown

I guess I do something very stupid but I can not realize what

this is my activity

package com.google.ads.example;

import com.google.ads.AdRequest;
import com.google.ads.AdSize;
import com.google.ads.AdView;

import android.app.Activity;
import android.os.Bundle;
import android.widget.LinearLayout;

public class BannerEssentials extends Activity{
  private static final String MY_BANNER_UNIT_ID = "123";

@Override
  public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // Lookup R.layout.main
    LinearLayout layout = (LinearLayout)findViewById(R.id.linearLayout);

    // Create the adView
    // Please replace MY_BANNER_UNIT_ID with your AdMob Publisher ID
    AdView adView = new AdView(this, AdSize.BANNER, MY_BANNER_UNIT_ID);

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

    // Initiate a generic request to load it with an ad
    AdRequest request = new AdRequest();
    request.setTesting(true);

    adView.loadAd(request);            
  }
}

this is my manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.google.ads.example"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".BannerEssentials"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="com.google.ads.AdActivity" 
              android:configChanges="keyboard|keyboardHidden|orientation"/>
    </application>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> 
    <uses-sdk android:minSdkVersion="3" />

</manifest> 

this is my layout main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/linearLayout"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello"
    />
</LinearLayout>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

酒几许 2024-12-22 00:15:53

您正在针对 Android API 13 编译您的项目吗?查看 admob 要求

要求
适用于 Android 的 Google AdMob 广告 SDK 需要 Android 1.5 或更高版本。确保您拥有最新的 Android SDK 副本,并且至少针对 Android v3.2 进行编译(将 default.properties 中的目标设置为 android-13)。

如果这没有帮助,请尝试从其官方网站下载并使用最新的 admob sdk。

Are you compiling your project against android API 13? Check out admob requirements:

Requirements
The Google AdMob Ads SDK for Android requires Android 1.5 or later. Make sure you have the latest copy of the Android SDK and that you're compiling against at least Android v3.2 (set target in default.properties to android-13).

If this does not help, try download and use the latest admob sdk from their official website.

缺⑴份安定 2024-12-22 00:15:53

尝试在 xml 文件中添加 admob 横幅 (http://code.google. com/mobile/ads/docs/android/banner_xml.html

请记住,即使一切正常,您也不会总是在应用程序中看到广告(阅读什么是填充率)

Try to add admob banner in xml file( http://code.google.com/mobile/ads/docs/android/banner_xml.html )

And remember that you won't always see ad in applicatio, even if everything works fine(read what is a fill rate)

假扮的天使 2024-12-22 00:15:53

您是否将 MY_BANNER_UNIT_ID 设置为您的实际发布商 ID?如果没有,您需要访问 AdMob 网站,注册并创建一个网站/应用来获取您的发布商ID。

仅供参考,4.0.4 是 SDK 的一个相当旧的版本。我建议升级到 4.3.1。 4.3.1 需要在清单中添加一些新的 configChanges,并要求您针对 android-13 进行编译(4.0.4 不需要),但它是一个更稳定且支持更完善的版本。您可以在此处找到有关集成 4.3.1 的文档。

Are you setting MY_BANNER_UNIT_ID to your actual publisher ID? If not, you need to go to the AdMob website, and sign up and create a site/app to get your publisher ID.

FYI, 4.0.4 is a pretty old version of the SDK. I would recommend upgrading to 4.3.1 instead. 4.3.1 requires a couple new configChanges in your manifest and requires you to compile against android-13 (4.0.4 does NOT), but it is a more stable and is a more well supported version. You can find documentation on integrating 4.3.1 here.

初心 2024-12-22 00:15:53

您需要在 admob 网站上手动添加您的应用程序。它会询问您的名称以及广告横幅或插页式广告的类型。即使我有发布者 ID,我的也没有显示,直到我手动添加它并点击页面底部的完成按钮。

You need to manually add your app on the admob site. It will ask you for the name and what type of ad banner or interstitial. Mine was not showing even though I had publisher ID, until I manually added it and hit the finish button at the bottom of the page.

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