Blog purpose for android basic example for android app developer. any query please my contact

Sunday, 10 May 2020

admob banner ads android tutorial

admob banner ads android tutorial

in this, an article today learn admob banner ads android tutorial example. Follow the steps of android banner ads example. For more information visit the google developer.

Banner ads involve a spot inside an application's design, either at the top or base of the gadget screen. They remain on screen while clients are associating with the application, and can revive naturally after a specific timeframe. In case you're new to mobile advertising, they're an extraordinary spot to begin.

 

Follow the method banner Ads :

MobileAds.initialize(this, (getString(R.string.ad_id)));

 

        mAdView = findViewById(R.id.adView1);

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

        mAdView.loadAd(adRequest);


build.gradle:

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

 

Follow the full source code  banner Ads android studio example.

1.MainActivity.java:

import android.webkit.WebViewClient;

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

public class Command extends AppCompatActivity {
 private AdView mAdView;

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


        MobileAds.initialize(this, (getString(R.string.ad_id)));

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

}


2.activity_main:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:id="@+id/main"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">

   

    <com.google.android.gms.ads.AdView
        android:id="@+id/adView1"
        ads:adSize="BANNER"
        ads:adUnitId="@string/banner_id"
        android:layout_width="match_parent"
        android:background="@android:color/transparent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true">
    </com.google.android.gms.ads.AdView>

</RelativeLayout>


3.string.xml:

<resources>
    <string name="app_name">Sql Application</string>
    <string name="ad_id">Your Ad Id</string>
    <string name="banner_id">Your Banner Id</string>
</resources>

4.dimens.xml:

<resources>
    <!-- Default screen margins, per the Android Design guidelines. -->
    <dimen name="activity_horizontal_margin">16dp</dimen>
    <dimen name="activity_vertical_margin">16dp</dimen>
    <dimen name="nav_header_vertical_spacing">8dp</dimen>
    <dimen name="nav_header_height">176dp</dimen>
    <dimen name="fab_margin">16dp</dimen>
</resources>

5.AndroidManifest.xml:


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.sql.commands.app">

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

    <application
        android:allowBackup="true"
        android:icon="@drawable/sql_image"
        android:label="@string/app_name"
        android:roundIcon="@drawable/sql_image"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".Policy"></activity>

        <meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="@string/ad_id" />

   
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>






No comments:

Post a Comment