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-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android: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
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.InterstitialAd;
@SuppressWarnings("deprecation")
public class MyActivity extends Activity
{
InterstitialAd mInterstitial;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
---------For Banner Ads--------------------------
AdView mAdView = new AdView(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 = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
layout.addView(mAdView, params);
mAdView.loadAd(new AdRequest.Builder().build());
------------For Interstitial Ads---------------------------------
mInterstitial = new InterstitialAd(this);
mInterstitial.setAdUnitId("ca-app-pub-7105659740979394/1209703665");
mInterstitial.loadAd(new AdRequest.Builder().build());
if (mInterstitial.isLoaded()) {
mInterstitial.show();
}
}
}

Jalankan Aplikasi anda dan lihat hasilnya

loading...

Tinggalkan Balasan

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