Dynamic load admob ads

<LinearLayout
	android:id="@+id/main_adTopBanner"
	android:orientation="vertical" 
	android:layout_height="50dp"
	android:layout_width="match_parent">        
</LinearLayout>


@Override
protected void onCreate(Bundle savedInstanceState)
{
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_main);

	LoadAds();			    	   
}
	
private AdView AD_TOP_BANNER = null;
public void LoadAds()
{
	// Create the adView.
	this.AD_TOP_BANNER = new AdView(this);
	this.AD_TOP_BANNER.setAdUnitId("MY_SPECIAL AND_UNIQUE_AD_ID");
	// this.AD_TOP_BANNER.setAdSize(AdSize.BANNER);
	this.AD_TOP_BANNER.setAdSize(AdSize.SMART_BANNER);

	// Lookup your LinearLayout assuming it's been given	
	LinearLayout layout = (LinearLayout) findViewById(R.id.main_adTopBanner);

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

	// Initiate a generic request.
	AdRequest adRequest = null;
	adRequest = new AdRequest.Builder().build();
	//FOR TESTING AND LOADING TEST ADS
	//adRequest = new AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR).addTestDevice("AC98C820A50B4AD8A2106EDE96FB87D4").build();	

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

0 Response to "Dynamic load admob ads"

Post a comment

Bila Ada posting yang kurang, atau error atau yang lainnya, silahkan tinggalkan komentar agar artikel/post di perbaiki.
Jangan Lupa Cek Box "Notify Me" agar tahu komentar kamu dibalas oleh saya.

If there are any posts that are missing, or error or anything else, please leave a comment for the article / post to be fixed.
Do not Forget Check Box "Notify Me" to know our comments replied by me.

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel