Skip to content

Library for Admob ads, to show and load ads with ease, Only you have to call functions and get results.

License

Notifications You must be signed in to change notification settings

ahmadidrees347/Admob-Ads

Repository files navigation

Using Admob Ads Library in your Android application

Add it in your root build.gradle at the end of repositories:

allprojects {
    repositories {
        maven { url 'https://jitpack.io' }
    }
}

Add this in your build.gradle

implementation 'com.github.ahmadidrees347:Admob-Ads:version'

Do not forget to add internet permission in manifest if already not present

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

For AdMob Ads, initialize it in onCreate() Method of Application/Activity class :

MobileAds.initialize(this)

For AppOpen ads, create an object, passing context & adUnitId in it;

val appOpen = AppOpen(application, Constants.AppOpenId)

setAdShownStatus(true/false), if you want to show ad every time then pass true.

appOpen.setAdShownStatus(false)

you can explicitly can call load or show function of appOpen ad:

appOpen.fetchAd { booleanStatus -> }
appOpen.showAdIfAvailable { booleanStatus -> }

For Interstitial:

For load an ad, call function, you get the result:

loadInterstitial(interAdId) { booleanStatus -> }

To show an ad, call function, you get the result:

showInterstitial(interAdId) { booleanStatus -> }

If you wanted to load an ad and show after loading, then call this function, you can pass any dialog which you want to show before showing an ad.

showInterOnDemand(interAdId, ProgressDialog(this)) { booleanStatus -> }

If you wanted to load every time, auto when user user dismiss an ad:

InterAdmobClass.adLoadAuto = true

You can set failed attempt for inter ad:

InterAdmobClass.adFailedAttempts = 3

For Banner ad,

Just pass id and frameLayout:

showAdmobBanner(bannerAdId, findViewById(R.id.bannerLayout))

If you wanted to check the banner is loaded or failed then call:

showAdmobBanner(bannerAdId, findViewById(R.id.bannerLayout),{
                       //success                                                         
            },{ error ->
                //failed
            })

For Native ad,

Just pass id, frameLayout and layout which you want to inflate:

loadNativeAdmob(
    findViewById(R.id.nativeLayout),
    nativeAdId,
    R.layout.custom_ad_large)

If you wanted to check the native is loaded or failed then call:

loadNativeAdmob(
    findViewById(R.id.nativeLayout),
    nativeAdId,
    R.layout.custom_ad_large,
    {
        //success
    }, { error ->
        //failed
    })

License

   Copyright (C) 2022 

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.