admob banner ads android 2019 | using Java Class

admob banner ads android 2019 | using Java Class


friends aaj mein app k sath share kar raha hon k app kis trah se admob banner ads android ko activity.xml k bagair java coding k sath laga skty hein

admob banner ads android 2019 | using Java Class
admob banner ads android 2019 | using Java Class



friend admob banner ads android 2019 ki implemetation k leay java, xml file and depencies neech laga raha hon aur last mein video share kar raha hon ais ko watch kar k aap easily admob banner ads ko android k leay implement kar skty hein 


  
Past dependency in build.gradle(module:app) 
in dependencies{

implementation 'com.google.android.gms:play-services-ads:17.2.0'
}



Now Past Below Code in Your Xml Activity in Layouts:

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:app="http://schemas.android.com/apk/res-auto"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    tools:context=".MainActivity">

    <TextView        android:layout_centerInParent="true"        android:gravity="center"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="Hello World!"        app:layout_constraintBottom_toBottomOf="parent"        app:layout_constraintLeft_toLeftOf="parent"        app:layout_constraintRight_toRightOf="parent"        app:layout_constraintTop_toTopOf="parent" />

    <RelativeLayout        android:gravity="center"        android:layout_centerInParent="true"        android:id="@+id/rlbanner"        android:layout_alignParentBottom="true"        android:layout_width="match_parent"        android:layout_height="wrap_content">

    </RelativeLayout>




</RelativeLayout>



Now Past this Java Code in Your Java.claas


import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.RelativeLayout;

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

public class MainActivity extends AppCompatActivity {

    AdView mAdview;

    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        BannerAds();



    }


    public void BannerAds(){


        View view = findViewById(R.id.rlbanner);
        mAdview = new AdView(MainActivity.this);
        mAdview.setAdSize(AdSize.BANNER);
        ((RelativeLayout) view).addView(mAdview);
        mAdview.setAdUnitId("ca-app-pub-3940256099942544/6300978111");
        AdRequest adRequest = new AdRequest.Builder().build();
        mAdview.loadAd(adRequest);

    }
} 

Now Past this code in manifest between Application

<application>
        <!-- Sample AdMob App ID: ca-app-pub-3940256099942544~3347511713 -->
        <meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="YOUR_ADMOB_APP_ID"/>
    </application>

Now Gave Internet Permission in Manifest

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

Watch Admob Banner Ads android 2019 full video toturial


Previous
Next Post »