2

我对 android 应用程序开发非常陌生,最后我几乎完成了一个应用程序,现在我正在尝试将 admob 添加到应用程序中,以便在下方显示广告。

我已经安装了 GoogleAdMobAdsSdkAndroid.zip 版本 6.1.0 并从谷歌下载了示例https://developers.google.com/mobile-ads-sdk/docs/android/fundamentals?hl=zh-CN并且有一个线

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

突出显示了错误 AD_UNIT_ID_GOES_HERE。

  1. 是我必须通过注册并获得一个 admob 帐户来替换上述 AD_UNIT_ID_GOES_HERE 吗?我还没有注册任何admob帐户。
  2. 如果我没有真正的 admob 帐户,那是不是就无法测试和预览广告?在我真正注册一个真实的 ID 之前,是否有任何 ID 仅用于测试目的?

java代码完全从上述谷歌网站复制并粘贴如下。android manifest 和 xml 也与 google 示例中的相同。

package com.google.example.ads.fundamentals;

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;

/**
 * A simple {@link Activity} that embeds an AdView.
 */
public class BannerSample extends Activity {
/** The view to show the ad. */
  private AdView adView;

  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // Create an ad.
    adView = new AdView(this, AdSize.BANNER, AD_UNIT_ID_GOES_HERE);

    // Add the AdView to the view hierarchy. The view will have no size
    // until the ad is loaded.
    LinearLayout layout = (LinearLayout) findViewById(R.id.linearLayout);
    layout.addView(adView);

    // Create an ad request. Check logcat output for the hashed device ID to
    // get test ads on a physical device.
    AdRequest adRequest = new AdRequest();
    adRequest.addTestDevice(AdRequest.TEST_EMULATOR);

    // Start loading the ad in the background.
    adView.loadAd(adRequest);
  }

  /** Called before the activity is destroyed. */
  @Override
  public void onDestroy() {
    // Destroy the AdView.
    if (adView != null) {
      adView.destroy();
    }

    super.onDestroy();
  }
}
4

3 回答 3

0

自己开个账号就行了。免费!

如果没有发布商 ID,您将无法展示广告。

在此处输入图像描述

于 2012-09-08T16:01:12.877 回答
0

使用此 adunit id 测试广告:adUnitId="a15391a0507f390"

于 2014-06-18T11:44:57.347 回答
0

对于AppID在新的 Admob 设计中。你可以进去View setup instructions

在此处输入图像描述

于 2016-11-27T06:26:37.877 回答