pearmak pearmak - 8 days ago 5
Android Question

android admob id

i am very new to the android app development, and i have just almost completed one app finally, and now i am trying to add admob to the app in order to show the ad undernearth.

i have installed that GoogleAdMobAdsSdkAndroid.zip version 6.1.0 and also downloaded the example from google at https://developers.google.com/mobile-ads-sdk/docs/android/fundamentals?hl=zh-CN and there is one line

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


that has bug AD_UNIT_ID_GOES_HERE highlighted.


  1. is that i must replace the above AD_UNIT_ID_GOES_HERE by registering and getting an admob account? I have not registered any admob account yet.

  2. Is that then i cannot test and preview about the ad if i have no true admob account? are there any ID available solely for testing purposes before i really register for a real one?



The java code is solely copied from the above google website and pasted as follows. android manifest and xml are also same as those in the google example.

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();
}
}

Answer

Just make yourself an account. It's free!

You can't show ads without an publisher id.

enter image description here

Comments