B4A Library FirebaseAdMob - Admob ads integrated with Firebase backend

Discussion in 'Additional libraries, classes and official updates' started by Erel, Jun 9, 2016.

  1. Erel

    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:
    Code:
    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, 0dip100%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.

    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/t...integrated-with-firebase-backend.67710/page-3
     

    Attached Files:

    Last edited: Oct 18, 2016
    yiankos1, eps, asales and 7 others like this.
  2. incendio

    incendio Active Member Licensed User

    Great, and when will B4A v6+ released?
     
  3. Erel

    Erel Administrator Staff Member Licensed User

    Very soon...
     
  4. tufanv

    tufanv Well-Known Member Licensed User

    Do we have to delete admob entry from manifest editor before adding the firebase admob to manifest ?
     
  5. Pendrush

    Pendrush Active Member Licensed User

    somed3v3loper and Erel like this.
  6. Erel

    Erel Administrator Staff Member Licensed User

    Note that you can make as many projects that you like in Firebase.
     
    Pendrush likes this.
  7. Douglas Farias

    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.

    [​IMG]
     
  8. Erel

    Erel Administrator Staff Member Licensed User

    Currently it only supports banner ads and interstitial ads.

    If anyone likes I can post the source code of this library.
     
    Douglas Farias and asales like this.
  9. Douglas Farias

    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
    Code:
    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
    Code:
    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: Jun 10, 2016
  10. Douglas Farias

    Douglas Farias Expert Licensed User

    @Erel
    Just a simple question.
    This lib need this?
    Code:
    #AdditionalJar: android-support-v4
    Like the old lib?

    thx
     
  11. Erel

    Erel Administrator Staff Member Licensed User

    No.
     
    eps and Douglas Farias like this.
  12. itgirl

    itgirl Active Member Licensed User

    can you plz share the source so maybe we can extend it to support the rest ads?
     
  13. Erel

    Erel Administrator Staff Member Licensed User

    Attached Files:

    • src.zip
      File size:
      2.5 KB
      Views:
      78
    koaunglay and itgirl like this.
  14. sorex

    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
     
  15. sorex

    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...
     
  16. sorex

    sorex Expert Licensed User

    Adding these extra libraries solved my problem
     
  17. sorex

    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.
     
  18. Erel

    Erel Administrator Staff Member Licensed User

    You shouldn't exclude any class as only the components required (based on the Maven dependencies files) are added.
     
  19. Douglas Farias

    Douglas Farias Expert Licensed User

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

    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:


    Code:
    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: Jul 4, 2016
  20. Computersmith64

    Computersmith64 Active 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:

    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.
     
Loading...