B4A Class FirebaseAdmob Native Ad Class

Discussion in 'Additional libraries, classes and official updates' started by Jack Cole, Jul 7, 2019.

  1. Jack Cole

    Jack Cole Active Member Licensed User

    Across the forum, there are pieces of code that you can put together to make native ads work. I put everything together into a class that saves me a lot of time, and hopefully you will find it helpful also.

    This example uses a pre-built layout and uses the Unified Native Ad for the type of native ad. Content and install ads are slated to be deprecated, so it would probably be a good idea to update your code to use the unified native ads.

    Getting started is pretty simple. Here is the code used in my attached example to load a native ad. Copy the layout file and class to your project. Don't forget to setup Firebase and add the related lines to the app manifest. Also, you need to replace the REPLACE_WITH_YOUR_NATIVE_AD_ID with your native ad id.

    One missing feature would be the ability to handle the event for a failure to load the ad. If anyone knows how to handle this, please post some code and I'll update it. If you make improvements to this class, please share!

    Sub Globals
    'These global variables will be redeclared each time the activity is created.
        'These variables can only be accessed from this module.
        Dim nuad As mwFirebaseAdmobNative
    End Sub
    Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    End Sub
    Sub Activity_Resume
    Dim testing=True As Boolean
    End Sub
    Sub Activity_Pause (UserClosed As Boolean)
    If nuad.IsInitialized Then nuad.RemoveView
    End Sub
    Private Sub nativead_ReceiveAd
    End Sub
    Thank you to Erel and asales. I used some information/code they provided in part of this class.


    Attached Files:

  2. Sasuke Sama

    Sasuke Sama Active Member Licensed User

    Ummm a noob question
    What is a nativeAd? Whats the different between it and a banner?
  3. Jack Cole

    Jack Cole Active Member Licensed User

    It's an ad that you can customize to look more "native" to your app. It is typically quite a bit larger than a banner ad.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice