17 Mar 2013

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. :)

Adding a com.google.ads.AdView

Android apps are composed of View 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 AdView instance
  • Create it, specifying a unit ID—your AdMob publisher ID
  • Add the view to the UI
  • Load it with an ad
The easiest place to do all this is in your app's Activity.

import 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 it's 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();
  }
}
You can download an example project containing this code here and may alternately

The Result

When you now run your app you should see a banner at the top of the screen:

0 comments

Post a Comment

JOM KLIK IKLAN

Blog Archive