Rabu, 12 Maret 2014
Browse Manual »
Wiring »
adsense
»
android
»
apps
»
buat
»
dengan
»
google
»
untuk
»
Buat dengan Google Adsense untuk apps Android
Assalamualaikum semua, kali ini Berita Hangit akan berikan Kod Google Adsense untuk Android.
Tentu ada dikalangan anda yang menggunakan Handphone, Tablet Android sebagai medium komunikasi seharian. Seperti yang kita pernah lihat, bagaimana orang menjana Buat Duit Dengan Applikasi Game. Lihat dibawah kod/skrip Google Adsense Untuk Android untuk menjana pendapatan secara rileks dengan android. :)
Like any
The five lines of code it takes to add a banner:
▸
Buat dengan Google Adsense untuk apps Android
Tentu ada dikalangan anda yang menggunakan Handphone, Tablet Android sebagai medium komunikasi seharian. Seperti yang kita pernah lihat, bagaimana orang menjana Buat Duit Dengan Applikasi Game. Lihat dibawah kod/skrip Google Adsense Untuk Android untuk menjana pendapatan secara rileks dengan android. :)
Adding a com.google.ads.AdView
Android apps are composed ofView objects, Java instances the user sees as text areas, buttons and other controls. AdView is simply another View subclass displaying small HTML5 ads that respond to user touch.Like any
View, an AdView may be created either purely in code or largely in XML.The five lines of code it takes to add a banner:
- Import
com.google.ads.* - Declare an
AdViewinstance - Create it, specifying a unit ID—your AdMob publisher ID
- Add the view to the UI
- Load it with an ad
Activity.You can download an example project containing this code here and may alternatelyimport com.google.ads.*;
public class BannerExample extends Activity {
private AdView adView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Create the adView
adView = new AdView(this, AdSize.BANNER, MY_AD_UNIT_ID);
// Lookup your LinearLayout assuming its been given
// the attribute android:id="@+id/mainLayout"
LinearLayout layout = (LinearLayout)findViewById(R.id.mainLayout);
// Add the adView to it
layout.addView(adView);
// Initiate a generic request to load it with an ad
adView.loadAd(new AdRequest());
}
@Override
public void onDestroy() {
if (adView != null) {
adView.destroy();
}
super.onDestroy();
}
}
create your banner in XML
Rather than creating yourAdView in Java, its also possible to set one up entirely in XML. To do so simply:- Incorporate the SDK into your app
- Define a
com.google.ads.AdViewinres/layout/main.xml, specifying it should immediately load an ad by using theads:loadAdOnCreateattribute. - Alternately, instead of forcing the
AdViewto load an ad immediately, Look up theAdViewas a resource at runtime and tell it to request an ad.
Defining a com.google.ads.AdView
The easiest way to incorporate an ad is to simply define yourAdView as you would any other part of your res/layout/main.xml:<?xml version="1.0" encoding="utf-8"?>As usual you must replace
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.google.ads.AdView android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="MY_AD_UNIT_ID"
ads:adSize="BANNER"
ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID"
ads:loadAdOnCreate="true"/>
</LinearLayout>
MY_AD_UNIT_ID with your AdMob publisher ID. You must also add your own device ID in the ads:testDevices attribute to get test ads on your device. Note the inclusion of the ads namespace referenced in specifying adUnitId and adSize. This code will immediately attempt to load an ad as soon as the AdView is created by Androids layout engine.Lookup and Load
If you have a need to control theAdRequest used to load an ad in your application, you can remove the ads:loadAdOnCreate="true" line from the above code. Instead, you will want to look up the AdView as a resource via findViewById and instruct it to loadAd:import com.google.ads.*;You can download an example project containing this code here.
public class BannerExample extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Look up the AdView as a resource and load a request.
AdView adView = (AdView)this.findViewById(R.id.adView);
adView.loadAd(new AdRequest());
}
}
The Result
When you now run your app you should see a banner at the top of the screen:
Langganan:
Posting Komentar (Atom)
Tidak ada komentar:
Posting Komentar