B4A Library FirebaseAdMob - Admob ads integrated with Firebase backend

Status
Not open for further replies.

Erel

Administrator
Staff member
Licensed User
This library required B4A v6+.

This library allows showing AdMob ads. It is integrated with Firebase services so you can better track and analyze the results.
https://firebase.google.com/docs/admob/

It supports banner ads and interstitial ads (full screen ads).

First you need to follow the Firebase integration tutorial: https://www.b4x.com/android/forum/threads/integrating-firebase-services.67692/
Make sure to include the Ads manifest snippet.

Full example that shows a banner ad and an interstitial ad when clicking on the activity:
B4X:
Sub Process_Globals

End Sub

Sub Globals
   Private BannerAd As AdView
   Private IAd As InterstitialAd
End Sub

Sub Activity_Create(FirstTime As Boolean)
   BannerAd.Initialize2("BannerAd", "ca-app-pub-3940256099942544/6300978111", BannerAd.SIZE_SMART_BANNER)
   Dim height As Int
   If GetDeviceLayoutValues.ApproximateScreenSize < 6 Then
    'phones
    If 100%x > 100%y Then height = 32dip Else height = 50dip
   Else
    'tablets
    height = 90dip
   End If
   Activity.AddView(BannerAd, 0dip, 100%y - height, 100%x, height)
   BannerAd.LoadAd
   IAd.Initialize("iad", "ca-app-pub-3940256099942544/1033173712")
   IAd.LoadAd
End Sub

Sub Activity_Click
   If IAd.Ready Then IAd.Show
End Sub

Sub IAD_AdClosed
   IAd.LoadAd 'prepare a new ad
End Sub
These are test ids and they will show test ads.

Edit: It is also required to request user consent for personalized ads. See this tutorial: https://www.b4x.com/android/forum/threads/firebaseadmob-and-user-consent.93347/#post-590593

V1.60 - Few new requirements, explained here: https://www.b4x.com/android/forum/threads/firebaseadmob-v1-6.108552/
V1.50 - Adds support for requesting consent.
V1.31 - Fixes an issue related to InMobi mediation ads.
V1.30 - Adds support for rewarded video ads: https://www.b4x.com/android/forum/threads/firebaseadmob-rewarded-video-ads.71430/
V1.20 - Adds support for native ads: https://www.b4x.com/android/forum/threads/firebaseadmob-admob-ads-integrated-with-firebase-backend.67710/page-3
 
Last edited:

Douglas Farias

Expert
Licensed User
hi @Erel
many thx for this lib.

one question.
i not tested the lib, because i dont have b4a 6, i m waiting the email :)

this lib will support native ads for listviews, clv etc..?
and the video ads too will support?


thx again.

 

Douglas Farias

Expert
Licensed User
erel what the avaible events?

IAD_AdClosed etc...

Have event about error? clicked, opened etc...

the iad here is never ready i need to know why :(


Edit. i found this
B4X:
Sub iad_AdClosed
    iad.LoadAd 'prepare a new ad
End Sub

Sub iad_ReceiveAd
    Log("Received")
End Sub

Sub iad_FailedToReceiveAd (ErrorCode As String)
    Log("not Received - " &"Error Code: "&ErrorCode)
    iad.LoadAd
End Sub

Sub iad_adopened
End Sub
----------------------------------------------------------------------

The problem now is the error code: 0

- Make new app intersticial and get the code OK
- Sync with firebase and put the package name to download the json file OK
- Put the json file on the app folder OK

- Download the last sdk, google play services and etc... OK
- Add the permisions code at manifest OK
https://www.b4x.com/android/forum/threads/integrating-firebase-services.67692/
i made all this tutorial.

- Start the iad OK
B4X:
   iad.Initialize("iad","ca-app-pub-xxxxxxxxxxxxxx/xxxxxxxxx")
   iad.LoadAd
Error Log : Code 0 FAIL

what can is this error? its new app made only to test, this is not on google play or banned.
the code and tutorials are ok


EDIT
I m reinstaled the google play services again and now its working

thx again
 
Last edited:

itgirl

Active Member
Licensed User
Currently it only supports banner ads and interstitial ads.

If anyone likes I can post the source code of this library.
can you plz share the source so maybe we can extend it to support the rest ads?
 

sorex

Expert
Licensed User
I upgraded to v6.0
I added the lib to my additional libs folder
refreshed the list
when I select the firebaseadmob library I get what you see in the picture below...

firebase.png
 

sorex

Expert
Licensed User
I just read I had to install additional stuff for v6.0, will do that first and give another status later...
 

sorex

Expert
Licensed User
first impressions...


it works ;) well done!


it's bloated > app went from 1.4Mb to 2.34Mb compared to the old admob+googleplayservices method.

not sure if we can exclude some of the stuff that's not required when just using the ads part?


I'm not sure about the benefits of this FireBase thing, maybe it reflects tomorrow when the data from my tests are visible in the reports.
 

Erel

Administrator
Staff member
Licensed User
not sure if we can exclude some of the stuff that's not required when just using the ads part?
You shouldn't exclude any class as only the components required (based on the Maven dependencies files) are added.
 

Douglas Farias

Expert
Licensed User
Hi @Erel
i m received this email from google admob, i dont know if cause any changes here.

Olá,
A AdMob tem o compromisso de fornecer a você as soluções de monetização mais eficazes. À medida que inovamos, é importante aproveitar as tecnologias mais recentes para incrementar nossa plataforma. Como parte desse movimento, desativaremos as versões 6.4.1 e anteriores do SDK dos anúncios para dispositivos móveis do Google no Android em 15 de setembro de 2016.
Para garantir a veiculação dos seus anúncios depois de 15 de setembro de 2016, faça upgrade para o SDK dos anúncios para dispositivos móveis do Google 7.0.0 ou posterior.
Os SDKs dos anúncios para dispositivos móveis do Google mais recentes têm muito mais vantagens para você:
  • Atualizações automáticas contínuas. Os usuários recebem as alterações no SDK dos anúncios para dispositivos móveis do Google no Android de forma contínua por meio dos serviços do Google Play para que você possa usar seu tempo no que é importante
    • Você não precisará passar tempo atualizando seus aplicativos com as versões mais recentes do SDK dos anúncios sempre que ele for alterado
    • Os usuários também receberão os novos recursos e as correções de bugs por meio de atualizações automáticas
  • Melhores experiências do usuário. O gerenciamento das atualizações dos aplicativos será mais fácil para os usuários, pois algumas melhorias serão recebidas automaticamente em segundo plano.
Para fazer upgrade do seu SDK, adicione a versão mais recente dos serviços do Google Play (em dependências) no seu arquivo de configuração do Gradle Build. Por exemplo, veja a seguir a adição da v9.0:
B4X:
apply plugin: 'com.android.application'
...
dependencies {
    compile 'com.google.android.gms:play-services:9.0.2'
}
Fique atento para mais atualizações e dicas.
Atenciosamente,
Equipe da AdMob
Hello,
AdMob is committed to providing you the most effective monetization solutions. As we innovate, it is important to use the latest technologies to enhance our platform. As part of this move, we will disable the 6.4.1 and earlier versions of Ads SDK for Google mobile on Android on September 15, 2016.
To ensure your ads run after September 15, 2016, upgrade to the SDK mobile ads Google 7.0.0 or later.
SDKs ads for the latest Google mobile devices have much more advantages for you:
Continuous automatic updates. Users receive the changes in Ads SDK for Google mobile on Android continuously through the Google Play services so you can use your time on what's important
You do not have to spend time updating your applications with the latest versions of the SDK ads whenever it changes
Users also receive new features and bug fixes through Automatic Updates
Best user experience. The management of the application updates will be easier for users because some improvements will be received automatically in the background.
To upgrade your SDK add the latest version of Google Play services (facilities) in your Gradle Build configuration file. For example, see the following addition of v9.0:


B4X:
apply plugin: 'com.android.application'
...
dependencies {
    compile 'com.google.android.gms:play-services:9.0.2'
}
Stay tuned for more updates and tips.
Regards,




this will change something in this library? or will not change anything?

ps: google play services now is REV 31

thx
 
Last edited:

Computersmith64

Well-Known Member
Licensed User
Hi Erel,

I also received the email from AdMob advising of the impending deprecation of SDK 6.4.1. I have been using the mwAdmobInterstitial2 library for a long time & it works great, however I don't know what version of the AdMob SDK it uses - so I thought I'd switch to AdMob through Firebase. I'm also using the Google Play Services library written by NFOBoy for leaderboards & achievements (I know it's an old library, but it has worked well for me) & now after switching Admob to Firebase, I get the following error when I compile the app:

B4A version: 6.00
Parsing code. (0.19s)
Running custom action. (0.04s)
Compiling code. (0.87s)
Compiling layouts code. (0.06s)
Organizing libraries. (2.43s)
Generating R file. (0.63s)
Compiling debugger engine code. (6.95s)
Compiling generated Java code. Error
B4A line: 2037
GGS.GamesClient.submitScore(gScores, CLng(Sta
javac 1.8.0_25
src\com\airlinemates\yahtzee\main.java:4750: error: cannot access OnAchievementsLoadedListener
mostCurrent._ggs.getGamesClient().submitScore(mostCurrent._gscores,_clng((Object)(mostCurrent._starter._iscore)));
^
class file for com.google.android.gms.games.achievement.OnAchievementsLoadedListener not found
I'm guessing that there's some kind of conflict between the version of Google Play Services that Firebase is using & the version (v14 I think) that NFOBoy's library is using?

- Colin.
 
Status
Not open for further replies.
Top