Free Download Software and Android Tutorials

Wednesday, August 12, 2015

Android studio tutorial learning inserts ID Interstitial Ads into the Application

Android Studio tutorial back discusses how to insert ID Interstitial ads into android application that we created; the aim is that the application can make money. In previous articles I have discussed about banner advertising insert ID into the application we created complete with examples that make the project directly. Admob advertising types other than the banner is Interstitial, where this type of advertising most widely yields when compared with the kind of banner ads.

Interstitial ads will display a full screen which makes it more users to click on these interstitial ads. For more details, now we just use the direct practice android studio, create a new project with the name IklanInterstitial, which the project will consist of MainActivity.java and activity_main.xml as layout. Here are pictures of steps made IklanInterstitial project.

android, studio, tutorial, learning, inserts, Interstitial, Ads, application

android, studio, tutorial, learning, inserts, Interstitial, Ads, application

android, studio, tutorial, learning, inserts, Interstitial, Ads, application

android, studio, tutorial, learning, inserts, Interstitial, Ads, application

Source code MainActivity.java
package com.dsoccerupdate.iklaninterstitial;

import com.google.android.gms.ads.AdListener;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.InterstitialAd;

import android.os.Bundle;
import android.widget.Toast;
import android.app.Activity;

public class MainActivity extends Activity {
    private InterstitialAd interstitial;

    @Override
    public void onCreate(Bundle SavedInstanceState) {
        super.onCreate(SavedInstanceState);
        setContentView(R.layout.activity_main);

        interstitial = new InterstitialAd(MainActivity.this);
        interstitial.setAdUnitId("ca-app-pub-8036741548724898/8307668162");
        AdRequest adRequest = new AdRequest.Builder()
                .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
                .addTestDevice("11F163F3EBE181DAB585531BBEF63689")
                .build();
        interstitial.loadAd(adRequest);

        interstitial.setAdListener(new AdListener() {
            public void onAdLoaded() {
                displayInterstitial();
            }

            @Override
            public void onAdFailedToLoad(int errorCode) {
                String message = String.format("onAdFailedToLoad (%s)", getErrorReason(errorCode));
                Toast.makeText(MainActivity.this, message, Toast.LENGTH_SHORT).show();
            }
        });
    }

    public void displayInterstitial() {
        if (interstitial.isLoaded()) {
            interstitial.show();
        }
    }

    private String getErrorReason(int errorCode) {
        String errorReason= "";
        switch (errorCode) {
            case AdRequest.ERROR_CODE_INTERNAL_ERROR:
                errorReason= "Internal error";
                break;
            case AdRequest.ERROR_CODE_INVALID_REQUEST:
                errorReason= "Invalid request";
                break;
            case AdRequest.ERROR_CODE_NETWORK_ERROR:
                errorReason= "Network error";
                break;
            case AdRequest.ERROR_CODE_NO_FILL:
                errorReason= "No Fill";
                break;
        }
        return errorReason;
    }
}

Source code activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">

</LinearLayout>

If you run the project outcome then the result will look like the image below

android, studio, tutorial, learning, inserts, Interstitial, Ads, application

So the studio android tutorial discusses how to insert ID Interstitial ads into applications that we make. If you follow continuously from the beginning to the end of this article I created, and then get here you can make android application that can generate money. Thank you for visiting this blog, continue to follow the latest articles from this blog.

Android studio tutorial learning inserts ID Interstitial Ads into the Application Rating: 4.5 Diposkan Oleh: Unknown

1 comments:

  1. Get daily suggestions and guides for making THOUSANDS OF DOLLARS per day FROM HOME totally FREE.
    JOIN NOW

    ReplyDelete