Jump to content

TextBin Online

TextBin is a website where you can store any text online for easy sharing.
Check It Out!
  • Welcome to PhCyber
  • Explore and Enjoy Browsing!
  • Lots of useful topics
  • Stay active and receive prizes

Banner Ads Android Code

Recommended Posts

 Step1 add depedencies:

 compile 'com.google.android.gms:play-services-ads:8.4.0'  


Step2 Add Android Manifest Permission:

<uses-permission android:name="android.permission.INTERNET" />  

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 


Step3 MainActivity.Java:

package com.eut.banner


import android.support.v7.app.AppCompatActivity;  

import android.os.Bundle;  


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

import com.google.android.gms.ads.AdView;  


public class MainActivity extends AppCompatActivity {  

    private AdView adView;  

    AdRequest adRequest;  


    protected void onCreate(Bundle savedInstanceState) {  



        adView = (AdView) findViewById(R.id.ad_view);  

        adRequest = new AdRequest.Builder().build();  






    public void onPause() {  

        if (adView != null) {  







    public void onResume() {  


        if (adView != null) {  






    public void onDestroy() {  

        if (adView != null) {  








Step4 Layout xml Add this to activity_main.xml




        android:text="Banner Ads Example" />  












Step5 Go to res values string.xml add this


    <string name="app_name">BannerAds</string>  

//replace unit ad to your original ad id

    <string name="banner_ad_unit_id">ca-app-pub-3940256099942544/6300978111</string>  



compile and build


Edited by SuperVegita1

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...