私はAndroidアプリの開発に非常に慣れていないので、ついに1つのアプリをほぼ完成させました。現在、広告を地下に表示するために、アプリにAdMobを追加しようとしています。
そのGoogleAdMobAdsSdkAndroid.zipバージョン6.1.0をインストールし、 https: //developers.google.com/mobile-ads-sdk/docs/android/fundamentals?hl=zh-CNでGoogleから例をダウンロードしました。ライン
adView = new AdView(this, AdSize.BANNER, AD_UNIT_ID_GOES_HERE);
バグAD_UNIT_ID_GOES_HEREが強調表示されています。
- 上記のAD_UNIT_ID_GOES_HEREを、AdMobアカウントを登録して取得することで置き換える必要がありますか?まだadmobアカウントを登録していません。
- それでは、本当のadmobアカウントを持っていない場合、広告についてテストしてプレビューすることはできませんか?実際に登録する前に、テスト目的でのみ使用できるIDはありますか?
Javaコードは、上記のgoogle Webサイトからのみコピーされ、次のように貼り付けられます。androidマニフェストと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();
}
}