Cara Pasang Iklan AdMob di Aplikasi/APK android

By |Februari 20, 2016

Buka AndroidManifest.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

<!-- admob required permissions integration -->
<uses-permissionandroid:name="android.permission.INTERNET"/>
<uses-permissionandroid:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permissionandroid:name="android.permission.ACCESS_WIFI_STATE"/>
<!-- End of admob permissions integration -->
   
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version"/>
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>

Untuk iklan Banner buka Layout.xml

1
2
3
4
5
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/mainLayout"
android:layout_alignParentTop="true"></RelativeLayout>

Buka MyActivity.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
importcom.google.android.gms.ads.AdRequest;
importcom.google.android.gms.ads.AdSize;
importcom.google.android.gms.ads.AdView;
importcom.google.android.gms.ads.InterstitialAd;
@SuppressWarnings("deprecation")
publicclassMyActivity extendsActivity
{
InterstitialAd mInterstitial;
@Override
protectedvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
---------For Banner Ads--------------------------
AdView mAdView = newAdView(Act_Change_Main_Background.this);
mAdView.setAdUnitId("ca-app-pub-7105659740979394/2826037666");
mAdView.setAdSize(AdSize.BANNER);
RelativeLayout layout = (RelativeLayout) findViewById(R.id.mainLayout);
RelativeLayout.LayoutParams params = newRelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
layout.addView(mAdView, params);
mAdView.loadAd(newAdRequest.Builder().build());
------------For Interstitial Ads---------------------------------
mInterstitial = newInterstitialAd(this);
mInterstitial.setAdUnitId("ca-app-pub-7105659740979394/1209703665");
mInterstitial.loadAd(newAdRequest.Builder().build());
if(mInterstitial.isLoaded()) {
mInterstitial.show();
}
}
}

Jalankan Aplikasi anda dan lihat hasilnya

Tinggalkan Balasan

Alamat email Anda tidak akan dipublikasikan. Ruas yang wajib ditandai *