Skip to content

Android lib to show admob ads according to the policies.

Notifications You must be signed in to change notification settings

tariqzia7523/AdsLib

Repository files navigation

AdsLib

This project contains library for easy implementation of ad mob according to ad policies.

implementation

Add flowing in maven { url 'https://jitpack.io' }

then following line in app gradle

implementation 'com.github.tariqzia7523:AdsLib:tag'

Usage

Add following to Manifest file in application tag

use your application id

GDPR Consent

On SplashScreen call following method, for more details look at SplashActivity in app

AddInitilizer(applicationContext,this,BuildConfig.DEBUG).getGDPRConsent("ca-app-pub-3940256099942544~3347511713",object : OnConsentResponse{
        override fun onConsentSuccess() {
            Toast.makeText(this@SplashActivity, "Suusess", Toast.LENGTH_SHORT).show()
           
        }

        override fun onConsentFailure(code: Int, message: String) {
            Toast.makeText(this@SplashActivity, "failure", Toast.LENGTH_SHORT).show()
            
        }
    })

OpenApp Add

Open app Ad is with different flow. For this make an application class in that add following code

class App : Application() {
    override fun onCreate() {
        super.onCreate()
        val mySharedPref = MySharedPref(this)
        mySharedPref.appOpenID ="orignal_app_id"
        AppOpenManager(this, this,mySharedPref,BuildConfig.DEBUG)
    }
}

In SplashClass implement OnSplashCallBack on class level and following line in oncreate

AppOpenManager.onSplashCallBack = this

    val mySharedPref = MySharedPref(this)
    mySharedPref.bannerID = "orignal_banner_id"
    mySharedPref.rewardID = "orignal_reward_id"
    mySharedPref.nativeID = "orignal_native_id"
    mySharedPref.interID = "orignal_interstitial_id"
    AddInitilizer.adCounter = 0

you will get method afterOpenAddCallBack. In this must add line

AppOpenManager.onSplashCallBack = null

add adjust furtherFlow

Interstitial Ad

implement interface on class level "OnAdsClosedCallBack" it will give you a method "onCallBack" which will trigger when interstitial call is closed

add following line in onResume Method

val addInitilizer = AddInitilizer(applicationContext,this,BuildConfig.DEBUG)

To show Interstitial Ad

addInitilizer.showInterstailAdd("Any tag")

onCallBack

you will get same tag in this method which is passed while calling the add yu can use that tag to differ in all further call

Banner Ad

addInitilizer.loadBanner(findViewById(R.id.banner_container))

Native ad

Add Following block in layout

 <RelativeLayout
    android:id="@+id/add_container"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/gnt_outline_shape"
    android:minHeight="@dimen/_130sdp"
    android:layout_marginLeft="@dimen/_10sdp"
    android:layout_marginRight="@dimen/_10sdp"
    android:layout_marginTop="@dimen/_10sdp"
    android:layout_alignParentBottom="true">

    <com.module.ads.TemplateView
        android:id="@+id/nativeTemplateView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:visibility="gone"
        app:gnt_template_type="@layout/gnt_small_template_view" />

        <!--  app:gnt_template_type="@layout/gnt_medium_template_view"  -->

    <TextView
        android:id="@+id/temp_add_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:text="@string/ad_will_display_hare" />
</RelativeLayout>

Add Following line in backend code

 addInitilizer.loadNativeAdd(findViewById(R.id.nativeTemplateView),findViewById(R.id.temp_add_text),findViewById(R.id.add_container))

InApp purcheses

project has in app purcheses to remove ad calls use following method. addInitilizer.goAddFree()

Showing ad in list (RecylerView)

val list = ArrayList()

    val myAdapterForAppList = MyAdapter(this@MainActivity, list)

    val admobNativeAdAdapter: AdmobNativeAdAdapter = AdmobNativeAdAdapter.Builder.with( this@MainActivity, myAdapterForAppList, "small", BuildConfig.DEBUG).adItemInterval(8).setContext(this@MainActivity).build()

    recylerView.layoutManager = LinearLayoutManager(this@MainActivity)

   recylerView.adapter = admobNativeAdAdapter

To Display add with madiation (fb-admob)

Add following in Application class

AddInitilizer.madiationInitilization(this)