README this doc to jumpstart your projects!
Explore the docs »
View Demo
·
Report Bug
·
Request Feature
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.
Create your own Anroid Application
-
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' }
-
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>
-
Download My McAdmobLibrary_1_0.aar
-
Import McAdmobLibrary_1_0.aar to your project root/libs/
- Sync McAdmobLibrary_1_0.aar to your project
- Start implement your project
Create your own Anroid Application
- 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.
- 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))
- 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)
- 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)
- 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()
}
}
Distributed under the MIT License. See LICENSE.txt
for more information.
Kuch Darith - [@kuchdarith][https://www.youtube.com/@kuchdarith] - kuchdarith@gmail.com
Project Link: [https://github.com/peterkuch/mcadmob][https://github.com/peterkuch/mcadmob]