Skip to content

peterkuch/mcadmob

Repository files navigation


Logo

Morecamboidda
In1 Educaion Game

README this doc to jumpstart your projects!
Explore the docs »

View Demo · Report Bug · Request Feature

About The Project

Add our McAdmobLibary to your own project , fast , easy, not take your own implement we are already handle for you. So what you have to do for required implement admob ad.

  • Create account with Admob and Follow : Regiser Admob
  • Follow Google Admob Doc : Quick-start
  • Import McAdmobLibary to your own project and start implement follow our document.

Getting Started

Installation

Create your own Anroid Application

  1. Add Grandle App Level , Google service dependencies

    dependencies {
         .....
         implementation 'com.google.android.gms:play-services-ads:22.1.0'
         implementation 'com.google.android.play:core:1.10.3'
    }
    
  2. Important to use Admob by add your Admob Account ID to your appliation manifest file. you can find from your admob account. Please replace your own Ads account to implement.

        <application>
             .....
              <meta-data
                 android:name="com.google.android.gms.ads.APPLICATION_ID"
                 android:value="ca-app-pub-3929444994565000~6715874000" />
        </application>
    
  3. Download My McAdmobLibrary_1_0.aar

  4. Import McAdmobLibrary_1_0.aar to your project root/libs/

  1. Sync McAdmobLibrary_1_0.aar to your project

  1. Start implement your project

Create your own Anroid Application

  1. Create if you want to implement banner admob before you use our lib , please create AdBanner contaner where you want to show in your project first, we required view from your app to show Banner Admob.

  1. Implement Banner Admob: parentview your place to show: R.id.adBanner
//Default Ads Debug
 AdmobService(this).setOnListener { status, adType, type, amount ->
            if (adType == AdmobService.AdType.AdView) {
                when (status) {
                    AdmobService.AdStatus.LOADED -> {
                        Log.i(tag, "AdView")
                    }

                    else -> {}
                }
            }
        }.onStartAdBanner(viewBanner = findViewById(R.id.adBanner))
 //Release Ads for prod add your own adUnitBanner
 AdmobService(this).setOnListener { status, adType, type, amount ->
            if (adType == AdmobService.AdType.AdView) {
                when (status) {
                    AdmobService.AdStatus.LOADED -> {
                        Log.i(tag, "AdView")
                    }

                    else -> {}
                }
            }
        }.onStartAdBanner(viewBanner = findViewById(R.id.adBanner, adUnitBanner = your own adUnitBanner))
  1. Implement InterstitialAd
//Default Ads Debug
AdmobService(this).setOnListener { status, adType, type, amount->
            if (adType == AdmobService.AdType.InterstitialAd) {
                when (status) {
                    AdmobService.AdStatus.LOADED -> {
                        Log.i(tag, "InterstitialAd")
                    }

                    else -> {

                    }
                }
            } else {

            }
        }.onStartAdInterstitial()
  //Release Ads for prod add your own adUnitInterstitial
  AdmobService(this).setOnListener { status, adType, type, amount->
            if (adType == AdmobService.AdType.InterstitialAd) {
                when (status) {
                    AdmobService.AdStatus.LOADED -> {
                        Log.i(tag, "InterstitialAd")
                    }

                    else -> {

                    }
                }
            } else {

            }
}.onStartAdInterstitial(your own adUnitInterstitial)
  1. Implement RewardedAd
//Default Ads Debug
AdmobService(this).setOnListener { status, adType, type, amount ->
            if (adType == AdmobService.AdType.RewardedAd) {
                when (status) {
                    AdmobService.AdStatus.REWARDED -> {
                       Log.i(tag, "REWARDED")
                    }

                    else -> {

                    }

                }
            } else {
            }
        }.onStartReward()
//Release Ads for prod add your own adUnitRewarded
AdmobService(this).setOnListener { status, adType, type, amount ->
            if (adType == AdmobService.AdType.RewardedAd) {
                when (status) {
                    AdmobService.AdStatus.REWARDED -> {
                       Log.i(tag, "REWARDED")
                    }

                    else -> {

                    }

                }
            } else {
            }
        }.onStartReward(your own adUnitRewarded)
  1. Final code
   class MainActivity : AppCompatActivity() {
    private var tag = "Admob Log"
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        findViewById<Button>(R.id.banner).setOnClickListener {
            loadBanner()
        }
        findViewById<Button>(R.id.intershow).setOnClickListener {
            loadInterstitialAd()
        }
        findViewById<Button>(R.id.reward).setOnClickListener {
            loadRewardedAd()
        }
    }
    /**
     * Load Admob banner
     */
    private fun loadBanner(){
        AdmobService(this).setOnListener { status, adType, type, amount ->
            if (adType == AdmobService.AdType.AdView) {
                when (status) {
                    AdmobService.AdStatus.LOADED -> {
                        Log.i(tag, "AdView")
                    }

                    else -> {}
                }
            }
        }.onStartAdBanner(viewBanner = findViewById(R.id.adBanner))
    }
    /**
     * Load Admob InterstitialAd
     */
    private fun loadInterstitialAd(){
        AdmobService(this).setOnListener { status, adType, type, amount->
            if (adType == AdmobService.AdType.InterstitialAd) {
                when (status) {
                    AdmobService.AdStatus.LOADED -> {
                        Log.i(tag, "InterstitialAd")
                    }

                    else -> {

                    }
                }
            } else {

            }
        }.onStartAdInterstitial()
    }
    /**
     * Load Admob RewardedAd
     */
    private fun loadRewardedAd(){
        AdmobService(this).setOnListener { status, adType, type, amount ->
            if (adType == AdmobService.AdType.RewardedAd) {
                when (status) {
                    AdmobService.AdStatus.REWARDED -> {
                        Log.i(tag, "REWARDED")
                    }

                    else -> {

                    }

                }
            } else {
            }
        }.onStartReward()
    }
}
  1. Final Demo IMAGE ALT TEXT HERE

License

Distributed under the MIT License. See LICENSE.txt for more information.

Contact

Kuch Darith - [@kuchdarith][https://www.youtube.com/@kuchdarith] - kuchdarith@gmail.com

Project Link: [https://github.com/peterkuch/mcadmob][https://github.com/peterkuch/mcadmob]