Posted by : Unknown Minggu, 22 April 2018


Nn: jika iklan tidak tampil maka ganti nama package menggunakan apk editor

Main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/t"
android:text="wait"/>

</LinearLayout>

MainActivity.java

package com.mycompany.myapp;

import android.app.*;
import android.os.*;
import com.google.android.gms.ads.MobileAds;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.InterstitialAd;
import com.google.android.gms.ads.AdListener;
import android.util.*;
import android.widget.*;

public class MainActivity extends Activity
{
private InterstitialAd mInterstitialAd;
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId("ca-app-pub-8053190329240173/4842633610");
mInterstitialAd.loadAd(new AdRequest.Builder().build());
mInterstitialAd.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {}
@Override
public void onAdFailedToLoad(int errorCode) {}
@Override
public void onAdOpened() {}
@Override
public void onAdLeftApplication() {}
@Override
public void onAdClosed() {
mInterstitialAd.loadAd(new AdRequest.Builder().build());
}});if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();}else{}}
@Override
public void onStart() {
super.onStart();
if(mInterstitialAd.isLoaded()) {
mInterstitialAd.show();}else{}

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.mycompany.myapp"
android:versionCode="2"
android:versionName="1.2">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="@android:style/Theme.Translucent" />

    </application>

</manifest>

Build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.0"

    defaultConfig {
        applicationId "com.mycompany.myapp"
        minSdkVersion 14
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
compile 'com.google.android.gms:play-services-ads:+'
compile 'com.google.android.gms:play-services-ads:+'
    compile fileTree(dir: 'libs', include: ['*.jar'])
}

Dikutip dari : http://www.sketchwarehelp.com/2017/09/how-to-integrate-admob-interstitial-ads.html?m=1

Leave a Reply

Subscribe to Posts | Subscribe to Comments

- Copyright © BLOG GUE WANGI - Blogger Templates - Powered by Blogger - Designed by Johanes Djogan -