Android Ad Manager Works with Admob, Mopup, Facebook- Bidding and Audience Networks

Overview

AndroidAdManager

  • Works with Admob, Mopup, Facebook- Bidding and Audience Networks.
  • Added ad types are NativeBanner, NativeAdvanced, Interstitial and Banner Ads for Facebook, Admob and MopUp.
  • By Default some fallback strategies are added for all Ads in case any fails other takes its place.
  • Ui Always stays stable, no displacement.
  • Shimmer animations while Ads is loaded.
  • Banner size is calculated automatically according to varying screen sizes.

To get a Git project into your build:

Step 1. Add the JitPack repository to your build file

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

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

Step 2. Add the dependency

dependencies {
        implementation 'com.github.hashimTahir:AndroidAdManager:1.0'
}

Step 3. Add the (Required) debug and release ids in the project level gradle file like so:

  resValue 'string', 'AdMob_AppId', '"ca-app-pub-3940256099942544~3347511713"'
  resValue 'string', 'Admob_BannerId', '"ca-app-pub-3940256099942544/6300978111"'
  resValue 'string', 'Admob_NativeAdvancedId', '"ca-app-pub-3940256099942544/2247696110"'
  resValue 'string', 'Admob_InterstitialId', '"ca-app-pub-3940256099942544/1033173712"'

  resValue 'string', 'Mopub_BannerId', 'b195f8dd8ded45fe847ad89ed1d016da'
  resValue 'string', 'Mopub_InterstitialId', '24534e1901884e398f1253216226017e'
  resValue 'string', 'Mopup_Native_BannerId', '"11a17b188668469fb0412708c3d16813"'

  resValue 'string', 'Fb_InterstitialId', 'abcd'
  resValue 'string', 'Fb_NativeAdvancedId', 'abcd'
  resValue 'string', 'Fb_Native_BannerId', '"abcd"'
  resValue 'string', 'Fb_BannerId', '"abcd"'

Step 4. Add the relevant strings in strings file

 <string name="admob_app_id">@string/AdMob_AppId</string>
 <string name="admob_banner_id">@string/Admob_BannerId</string>
 <string name="admob_native_advanced_id">@string/Admob_NativeAdvancedId</string>
 <string name="admob_interstitial_id">@string/Admob_InterstitialId</string>

 <string name="fb_interstitial_id">@string/Fb_InterstitialId</string>
 <string name="fb_native_advanced_id">@string/Fb_NativeAdvancedId</string>
 <string name="fb_native_banner_id">@string/Fb_Native_BannerId</string>
 <string name="fb_banner_id">@string/Fb_BannerId</string>

 <string name="mopub_banner_id">@string/Mopub_BannerId</string>
 <string name="mopub_interstitial_id">@string/Mopub_InterstitialId</string>
 <string name="mopup_native_banner_id">@string/Mopup_Native_BannerId</string>

Step 5. Initialize the AndroidAdManager in Application class. by passing the Required

ids and context in the Admanager's constructor.

 val hIdsMap = hashMapOf<AdsType, HashMap<WhatAd, String>>()
 val hAdMobMap = hashMapOf<WhatAd, String>()
 val hMopUpMap = hashMapOf<WhatAd, String>()
 val hFacebookMap = hashMapOf<WhatAd, String>()

 hAdMobMap[WhatAd.H_NATIVE_ADVANCED] = getString(R.string.admob_native_advanced_id)
 hAdMobMap[WhatAd.H_NATIVE_BANNER] = getString(R.string.admob_native_advanced_id)
 hAdMobMap[WhatAd.H_BANNER] = getString(R.string.admob_banner_id)
 hAdMobMap[WhatAd.H_INTER] = getString(R.string.admob_interstitial_id)


 hMopUpMap[WhatAd.H_NATIVE_ADVANCED] = getString(R.string.mopup_native_banner_id)
 hMopUpMap[WhatAd.H_NATIVE_BANNER] = getString(R.string.mopup_native_banner_id)
 hMopUpMap[WhatAd.H_BANNER] = getString(R.string.mopub_banner_id)
 hMopUpMap[WhatAd.H_INTER] = getString(R.string.mopub_interstitial_id)

 hFacebookMap[WhatAd.H_NATIVE_ADVANCED] = getString(R.string.fb_native_advanced_id)
 hFacebookMap[WhatAd.H_NATIVE_BANNER] = getString(R.string.fb_native_banner_id)
 hFacebookMap[WhatAd.H_BANNER] = getString(R.string.fb_banner_id)
 hFacebookMap[WhatAd.H_INTER] = getString(R.string.fb_interstitial_id)

 hIdsMap[AdsType.H_ADMOB] = hAdMobMap
 hIdsMap[AdsType.H_FACEBOOK] = hFacebookMap
 hIdsMap[AdsType.H_MOPUP] = hMopUpMap

 AdManager.hInitializeAds(
        this,
        hIdsMap
    )

Step 6. By default all priorities are set to Admob->MopUp->Facebook-None. if one fails,

other takes its place. To change the priorities use following methods:

 AdManager.hSetNativeAdvancedPriority(AdPriorityType.H_MOP_UP)
 AdManager.hSetNativeBannerPriority(AdPriorityType.H_MOP_UP)   

Above methods change the priorities to MopUp->AdMob-Facebook->None. Strategies can be

found in "fallbackstrategies" package. To create ur own, create a class which extends the

"Strategy" interface.

Step 7. Call the relevant methods from Ui to display Ads.

 AdManager.hShowNativeAdvanced(hMainBinding.hNativeAdvancedBanner)
 AdManager.hShowNativeBanner(hMainBinding.hNativeBanner)
 AdManager.hShowBanner(hMainBinding.hBannerContainer)

If you don't want to fallback to others Ads and only use fixed Ads then use the following

methods.

  AdManager.hShowNativeBannerWithOutFallback(
        hMainBinding.hNativeBanner,
        AdPriorityType.H_MOP_UP
    )
  AdManager.hShowBannerWithOutFallback(
  hMainBinding.hNativeBanner,
  AdPriorityType.H_MOP_UP
   )
  AdManager.hShowNativeAdvancedWithOutFallback(
  hMainBinding.hNativeAdvancedBanner,
  AdPriorityType.H_MOP_UP
  )

Above methods will only show Mopup Ads, if it fails, none will be shown in its place.

By default AdContainers i.e. HnativeBannerView and HnativeAdvacncedView are rounded and

are given app's primary color and stroke. To change use method:

 fun hSetBackGroundDrawable(
    hBackgroundColor: Int,
    hCornerRadius: Int = 6,
    hStroke: Stroke = Stroke(context)
) {
    val hGradientDrawable = GradientDrawable()
    hGradientDrawable.apply {
        setColor(hBackgroundColor)
        cornerRadius = hDp(context, hCornerRadius)
        setStroke(
            hStroke.hWidth,
            hStroke.hColor
        )
        hLayoutHAdcontainerBinding.hAdRootCL.background = hGradientDrawable
    }
}

Or Change from layout as:

 <com.hashim.hadmanager.adsmodule.customadview.HnativeBannerView
 android:id="@+id/hNativeBanner"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 app:hBackgroundColor="@color/black"
 app:hCornerRadius="6"
 app:hStrokeWidth="6"
 app:hStrokeColor="@color/black"
 app:layout_constraintEnd_toEndOf="parent"
 app:layout_constraintStart_toStartOf="parent"
 app:layout_constraintTop_toBottomOf="@id/hNativeAdvancedBanner" />

To Show you own Holder while ad is loading over NativeAdvanced use following:

 <com.hashim.hadmanager.adsmodule.customadview.HnativeAdvancedView
 android:id="@+id/hNativeAdvancedBanner"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 app:hLoaderContainer="@layout/native_advanced_alternative"
 app:layout_constraintEnd_toEndOf="parent"
 app:layout_constraintStart_toStartOf="parent"
 app:layout_constraintTop_toTopOf="parent" />

Where native_advanced_alternative is your own Holder containing anything, Image,

animations. etc.

View when ad is loading

ScreenShot ScreenShot

View when ad is loaded

ScreenShot ScreenShot

You might also like...
YouTube Player library for Android and Chromecast, stable and customizable.
YouTube Player library for Android and Chromecast, stable and customizable.

android-youtube-player android-youtube-player is a stable and customizable open source YouTube player for Android. It provides a simple View that can

πŸ› οΈ The missing drawable toolbox for Android. Create drawables programmatically and get rid of the boring and always repeated drawable.xml files.
πŸ› οΈ The missing drawable toolbox for Android. Create drawables programmatically and get rid of the boring and always repeated drawable.xml files.

DrawableToolbox English | δΈ­ζ–‡ The missing DrawableToolbox for Android. Create drawables programmatically and get rid of the boring and always repeated

The most complete and powerful data-binding library and persistence infra for Kotlin 1.3, Android & Splitties Views DSL, JavaFX & TornadoFX, JSON, JDBC & SQLite, SharedPreferences.

Lychee (ex. reactive-properties) Lychee is a library to rule all the data. ToC Approach to declaring data Properties Other data-binding libraries Prop

A Kotlin Multiplatform and Compose template that allows you to easily set up your project targeting: Android, Desktop, and Web

A Kotlin Multiplatform and Compose template that allows you to easily set up your project targeting: Android, Desktop, and Web

Unsplash application for Android, Desktop and Web. Built using Kotlin Multiplatform and Compose
Unsplash application for Android, Desktop and Web. Built using Kotlin Multiplatform and Compose

Unsplash Unsplash application for Android, Desktop and Web. Built using Kotlin Multiplatform and Compose with ❀️ πŸ‘‰ Presentation Set up the environmen

Delish, a Food Recipes App in Jetpack Compose and Hilt based on modern Android tech-stacks and MVVM clean architecture.
Delish, a Food Recipes App in Jetpack Compose and Hilt based on modern Android tech-stacks and MVVM clean architecture.

Delish Screens Tech stack & Open-source libraries 100% Kotlin based + Coroutines + Flow for asynchronous. Dagger Hilt 2.37 Accompanist JetPack Jetpack

A secure, opensource android app to store your bank accounts, cards, and credentials. Locally and securely.
A secure, opensource android app to store your bank accounts, cards, and credentials. Locally and securely.

Digital Tijori πŸ”’ Digital Tijori app lets you store your bank accounts, cards and credentials. You can link cards and credentials to a particular bank

A android platform i.e, App that helps marriage/party halls and individuals to connect to the nearest places where this food could feed those in need and food wastage is minimised

(Muskan- The joy of giving by nature) , a android platform i.e, App that helps marriage/party halls and individuals to connect to the nearest places where this food could feed those in need and food wastage is minimised.

This library provides common speech features for ASR including MFCCs and filterbank energies for Android and iOS.

Kotlin Speech Features Quick Links πŸ“’ Introduction This library is a complete port of python_speech_features in pure Kotlin available for Android and

Releases(1.6)
Owner
Hashim Tahir
Hashim Tahir
A Kotlin work manager library for Android with progress notifications and Hilt support.

Boot Laces A kotlin work manager library for Android that includes notifications and Hilt support. User Instructions Add the JitPack repository to you

Chris Basinger 35 Oct 8, 2022
Location Service Manager for Kotlin Multiplatform Mobile iOS and android

Location Service Manager for Kotlin Multiplatform Mobile iOS and android Features Provides simple permission settings Dramatically reduce the amount o

LINE 55 Dec 10, 2022
Carousel Recyclerview let's you create carousel layout with the power of recyclerview by creating custom layout manager.

Carousel Recyclerview Create carousel effect in recyclerview with the CarouselRecyclerview in a simple way. Including in your project Gradle Add below

Jack and phantom 514 Jan 8, 2023
An easy to use package manager for Fabric Minecraft mods.

pacmc pacmc is a package manager for Fabric Minecraft mods. The aim of this project is to massively reduce the effort you have to put in to installing

Jakob K 109 Dec 30, 2022
Strong-bax - An open source password manager project

What is strong-bax? Strong-bax is an open source password manager project. Stron

null 1 Feb 6, 2022
Reapp is everything you need to build amazing apps with React: a collection of packages that work together, our UI kit, and a CLI that scaffolds your app and includes a server and build system.

What is it? Reapp is everything you need to build amazing apps with React: a collection of packages that work together, our UI kit, and a CLI that sca

reapp 3.4k Nov 20, 2022
Create an application with Kotlin/JVM and Kotlin/JS, and explore features around code sharing, serialization, server- and client

Practical Kotlin Multiplatform on the Web λ³Έ μ €μž₯μ†ŒλŠ” μ½”ν‹€λ¦° λ©€ν‹°ν”Œλž«νΌ 기반 μ›Ή ν”„λ‘œκ·Έλž˜λ° μ›Œν¬μˆ(κ°•μ’Œ)을 μœ„ν•΄ μž‘μ„±λœ ν…œν”Œλ¦Ώ ν”„λ‘œμ νŠΈκ°€ μžˆλŠ” κ³³μž…λ‹ˆλ‹€. μ›Œν¬μˆ κ³Όμ •μ—μ„œ μ½”ν‹€λ¦° λ©€ν‹°ν”Œλž«νΌμ„ 기반으둜 ν”„λ‘ νŠΈμ—”λ“œ(front-end)λŠ” Ko

SpringRunner 14 Nov 5, 2022
A tiny Kotlin multiplatform library that assists in saving and restoring objects to and from disk using kotlinx.coroutines, kotlinx.serialisation and okio

Store A tiny Kotlin multiplatform library that assists in saving and restoring objects to and from disk using kotlinx.coroutines, kotlinx.serialisatio

Isuru Rajapakse 98 Jan 3, 2023
Create an application with Kotlin/JVM and Kotlin/JS, and explore features around code sharing, serialization, server- and client

Building a Full Stack Web App with Kotlin Multiplatform λ³Έ μ €μž₯μ†ŒλŠ” INFCON 2022μ—μ„œ μ½”ν‹€λ¦° λ©€ν‹°ν”Œλž«νΌ 기반 μ›Ή ν”„λ‘œκ·Έλž˜λ° ν•Έμ¦ˆμ˜¨λž©μ„ μœ„ν•΄ μž‘μ„±λœ ν…œν”Œλ¦Ώ ν”„λ‘œμ νŠΈκ°€ μžˆλŠ” κ³³μž…λ‹ˆλ‹€. ν•Έμ¦ˆμ˜¨ κ³Όμ •μ—μ„œ μ½”ν‹€λ¦° λ©€ν‹°ν”Œλž«νΌμ„

Arawn Park 19 Sep 8, 2022
Bego Chat is chat application in Kotlin and Firebase with the following features: last seen , user status like typing ,online and last seen with MVVM pattern and clean architecture

Compose ChatApp(Bego Chat) Bego Chat is Compose chat application in Kotlin and Firebase with the following features: sending all file types and abilit

Ahmed EL Bagory 5 Dec 20, 2022