Android Example [B4XPages] Admob Example

Check this other excellent example from @Jack Cole.

To help the new members to make money with B4A, I tried to compile all the relevant Admob code (except mediation) of the forum in this example and put comments and links.
This is a work in progress.
Any code and sample to improve this example are welcome.

Follow these instructions to start:
1. Integrating Firebase Services
- https://www.b4x.com/android/forum/threads/integrating-firebase-services.67692/
2. FirebaseAdMob - Admob ads integrated with Firebase backend
- https://www.b4x.com/android/forum/t...tegrated-with-firebase-backend.67710/#content
3. FirebaseAdMob v1.6
- https://www.b4x.com/android/forum/threads/firebaseadmob-v1-6.108552/
4. B4A 9.90 and SDK Manager up to date.

Update 6.0:
- Adaptive banner with customlistview

Update 5.0:
- Rewarded Video and Rewarded Interstitial Ads
- AdsHelper updated with code from Jack Cole. Thanks!

Update 4.0:
- removed transitions code to fix this error
- example code to adjust volume level
B4X:
Dim volume As Float = 0.5
jo.RunMethod("setAppVolume", Array(volume))

Update 3.0:
The example was updated with some changes made with the FirebaseAdmob2 lib.
- new lib: FirebaseAdmob2
- change SIZE_SMART_BANNER format to Adaptive Banner
- AdsHelper Class
- Rewarded video ad removed
- App Open Ad included

Updated 2.0 (B4XPages_Admob_Example):
- B4XPages
- Transition in Interstitial ad (requires Reflection library)
- Code to mute the ad sound
- Banner in a panel

This is not a (almost) definitive example anymore, like the old title said.

1690758087061.png
 

Attachments

  • b4xpages_admob_example6.zip
    57.8 KB · Views: 78
Last edited:

Mike1970

Well-Known Member
Licensed User
Longtime User
GREAT WORK. With the tutorials on the forum i couldn't get a functioning example. But with this i can finally start to study this thing.

However there is an error in the "Banner Module"

Line 116
B4X:
java.lang.RuntimeException: Method: getCurrentOrientationAnchoredAdaptiveBannerAdSize not found in: com.google.android.gms.ads.AdSize
 

asales

Expert
Licensed User
Longtime User
However there is an error in the "Banner Module"
It uses the new adaptive banners:
Minimum version of artifact: 18.3.0
Solution
: Start SDK Manager and download/update all the recommended items.
 
Last edited:

Mike1970

Well-Known Member
Licensed User
Longtime User
It uses the new adaptive banners:
Minimum version of artifact: 18.3.0
Solution
: Start SDK Manager and download/update all the recommended items.
Strange.. i already did it. Nothing changed
 
Last edited:

Michele Balzano

New Member
Licensed User
Longtime User
Ho provato ad utilizzare il codice con l'ultima versione di B4A, ma ricevo sempre l'errore
Errore analisi google-services.json:
Il file 'C: \ Users \ miche \ OneDrive \ Desktop \ AdmobExample_Forum \ google-services.json' non è stato trovato. dove posso scaricare il file?
grazie
 

Mike1970

Well-Known Member
Licensed User
Longtime User
Ho provato ad utilizzare il codice con l'ultima versione di B4A, ma ricevo sempre l'errore
Errore analisi google-services.json:
Il file 'C: \ Users \ miche \ OneDrive \ Desktop \ AdmobExample_Forum \ google-services.json' non è stato trovato. dove posso scaricare il file?
grazie
You must follow the Erel’s guide about the integration of Firebase here, there is a step where you have to download that file and put it in the app folder
 

SMOOTSARA

Active Member
Licensed User
Longtime User
To help the new members to make money with B4A, I tried to compile all the relevant Admob code (except mediation) of the forum in this example and put comments and links.
This is a work in progress.
Any code and sample to improve this example are welcome.

Follow these instructions to start:
1. Integrating Firebase Services
- https://www.b4x.com/android/forum/threads/integrating-firebase-services.67692/
2. FirebaseAdMob - Admob ads integrated with Firebase backend
- https://www.b4x.com/android/forum/t...tegrated-with-firebase-backend.67710/#content
3. FirebaseAdMob v1.6
- https://www.b4x.com/android/forum/threads/firebaseadmob-v1-6.108552/
4. B4A 9.80 and SDK Manager up to date.

View attachment 88140


Hi asales
Thank you very much for this example

The program gives an error without any log as long as this line of code is active in the manifest.
As soon as you comment on this line, the program will work properly. What is the reason?

B4X:
'************ Firebase Base (end) ************'************ Firebase Ads ************
'CreateResourceFromFile(Macro, FirebaseAdMob.FirebaseAds)
 

SMOOTSARA

Active Member
Licensed User
Longtime User
Hi @asales

You may complete click-through activity on native ads. ?
After clicking, we have to go back to the app and load the new ads.
How is this process done?

Thank you for your kindness and guidance.
 

asales

Expert
Licensed User
Longtime User
Hi asales
The program gives an error without any log as long as this line of code is active in the manifest.
- Check the unfiltered logs
- The B4A version and the FirebaseAdMob lib is up to date?
- Did you follow this instructions?
 

asales

Expert
Licensed User
Longtime User
Hi @asales
You may complete click-through activity on native ads. ?
After clicking, we have to go back to the app and load the new ads.
How is this process done?
This ads is different from the others. Try with the "_clicked" event.
Google is not serving tests ads to my app (lack of inventory) and, for this, I can't check this option.
 

Lyndon Bermoy

Active Member
Licensed User
Longtime User
The real ads are now showing using the debug keys. All thanks to you @asales :) But when I created my private sign key, the real ads now won't appear but when I use debug key then the real ads will appear again. How to fix this? I want to upload my first app in Playstore since I already have the Google Developer account.
 

asales

Expert
Licensed User
Longtime User
A new example was attached in the first post.
Updated with:
- B4XPages
- Transition in Interstitial ad (requires Reflection library)
- Code to mute the ad sound
- Banner in a panel ( @AnandGupta )
 
Last edited:

azad222

Member
To help the new members to make money with B4A, I tried to compile all the relevant Admob code (except mediation) of the forum in this example and put comments and links.
This is a work in progress.
Any code and sample to improve this example are welcome.

Follow these instructions to start:
1. Integrating Firebase Services
- https://www.b4x.com/android/forum/threads/integrating-firebase-services.67692/
2. FirebaseAdMob - Admob ads integrated with Firebase backend
- https://www.b4x.com/android/forum/t...tegrated-with-firebase-backend.67710/#content
3. FirebaseAdMob v1.6
- https://www.b4x.com/android/forum/threads/firebaseadmob-v1-6.108552/
4. B4A 9.90 and SDK Manager up to date.

Updated 2.0 (B4XPages_Admob_Example):
- B4XPages
- Transition in Interstitial ad (requires Reflection library)
- Code to mute the ad sound
- Banner in a panel

View attachment 88140

An error occurred after execution. stop program.
I tried it on Android 4.2 and 10.
 

Attachments

  • erorb4a.jpg
    erorb4a.jpg
    20.9 KB · Views: 481

asales

Expert
Licensed User
Longtime User
Update 4.0:
- removed transitions code to fix this error
- example code to adjust volume level
B4X:
Dim jo As JavaObject
jo.InitializeStatic("com.google.android.gms.ads.MobileAds")
Dim volume As Float = 0.5
jo.RunMethod("setAppVolume", Array(volume))
 
Top