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
AdView
instance - 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();
}
}
The Result
When you now run your app you should see a banner at the top of the screen:
0 komentar:
Posting Komentar