How To Admob Boost Show Banner Every 20 Seconds In An Android Application (Fragment)

in #utopian-io7 years ago (edited)

Introduction

Android is one of the most popular operating systems for mobile. In this article, I will show you how to show Banner ads every 20 seconds in an Android application using Android Studio

Screenshot_7.jpg

Requirements

Android Studio version 2.3.3
Little bit XML and JAVA knowledge.
Android Emulator (or) Android mobile
Download link (Android Studio)

Steps to should be followed

Follow these steps to show interstitial ads every 20 seconds in an Android application. I have included the source code below.

Step 1

Open Android Studio and start a New Android Studio Project.

Step 2

You can choose your application name and choose the location where your project is to be stored. If you wish to use C++ for coding the project, mark the "Include C++ support", and click "Next" button.

Screenshot_2.jpg

Now, select the version of Android and select the target Android devices.

Screenshot_3.jpg

Step 3

Now, add the activity and click "Next" button.

Screenshot_4.jpg

Add Activity name and click "Finish".

The java code is given below. Modif by me

package business.visored.com.visored;

import android.app.Fragment;
import android.app.FragmentManager;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.RelativeLayout;

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

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**

  • Created by Kuncoro on 22/03/2016.
    */
    public class Import extends Fragment {

    public Import(){}
    RelativeLayout view;
    private AdView mAdView;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {



    view = (RelativeLayout) inflater.inflate(R.layout.import_main, container, false);
    getActivity().setTitle("Banner");





    Button button = (Button) view.findViewById(R.id.button2);
    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            //place your action here




        }
    });

    ScheduledExecutorService scheduleTaskExecutor = Executors.newScheduledThreadPool(5);
    scheduleTaskExecutor.scheduleAtFixedRate(new Runnable() {

        public void run() {
            getActivity().runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    mAdView = (AdView) view.findViewById(R.id.adView);
                    AdRequest adRequest = new AdRequest.Builder().build();
                    mAdView.loadAd(adRequest);

                    mAdView = (AdView) view.findViewById(R.id.adView1);
                    AdRequest adRequest1 = new AdRequest.Builder().build();
                    mAdView.loadAd(adRequest);

                    mAdView = (AdView) view.findViewById(R.id.adView2);
                    AdRequest adRequest2 = new AdRequest.Builder().build();
                    mAdView.loadAd(adRequest);

                    mAdView = (AdView) view.findViewById(R.id.adView3);
                    AdRequest adRequest3 = new AdRequest.Builder().build();
                    mAdView.loadAd(adRequest);

                    mAdView = (AdView) view.findViewById(R.id.adView4);
                    AdRequest adRequest4 = new AdRequest.Builder().build();
                    mAdView.loadAd(adRequest);


                    mAdView = (AdView) view.findViewById(R.id.adView5);
                    AdRequest adRequest5 = new AdRequest.Builder().build();
                    mAdView.loadAd(adRequest);


                }
            });
        }
    }, 0, 1, TimeUnit.SECONDS);



    return view;
}

}

Layout

Screenshot_6.jpg

Finish



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Your contribution cannot be approved yet, because it is in the wrong category. The correct category for your post is Tutorials. See the Utopian Rules. Please edit your post to use the right category at this link, as shown below:

You can contact us on Discord.
[utopian-moderator]

Your contribution cannot be approved because it does not follow the Utopian Rules.

The article has been submitted in the wrong category, and you have not changed this within 48 hours of the request to do so.

You can contact us on Discord.
[utopian-moderator]

Coin Marketplace

STEEM 0.16
TRX 0.17
JST 0.029
BTC 69940.74
ETH 2517.95
USDT 1.00
SBD 2.55