B4A Library AppBrain Ads

Discussion in 'Additional libraries, classes and official updates' started by Erel, Mar 21, 2018.

  1. Erel

    Erel Administrator Staff Member Licensed User

    1. Register with AppBrain: https://www.appbrain.com/

    2. Download their AAR and copy it to the additional libraries folder: https://github.com/swisscodemonkeys/appbrain-sdk/releases/latest

    3. Add to manifest editor:
    Code:
    '**************  AppBrain
    AddPermission(android.permission.INTERNET)
    AddPermission(android.permission.ACCESS_NETWORK_STATE)
    AddApplicationText(
       <
    activity
                android:name=
    "com.appbrain.AppBrainActivity"
                android:configChanges=
    "keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />

            <provider
                android:name=
    "com.appbrain.AppBrainInitProvider"
                android:authorities=
    "${applicationId}.AppBrainInitProvider"
                android:exported=
    "false" />

            <
    service android:name="com.appbrain.AppBrainService" />
            <
    service
                android:name=
    "com.appbrain.AppBrainJobService"
                android:enabled=
    "@bool/appbrain_job_service_enabled"
                android:permission=
    "android.permission.BIND_JOB_SERVICE" />

            <receiver
                android:name=
    "com.appbrain.ReferrerReceiver"
                android:exported=
    "true" >
                <
    intent-filter>
                    <action android:name=
    "com.android.vending.INSTALL_REFERRER" />
                </
    intent-filter>
            </receiver>
    )
    '*********************
    4. Add a reference to the downloaded AAR:
    Code:
    #AdditionalJar: appbrain-sdk-14.10.aar
    5. Code to create an interstitial ad:
    Code:
    Sub Globals
       
    Private ad As JavaObject
       
    Private ctxt As JavaObject
    End Sub

    Sub Activity_Create(FirstTime As Boolean)
       
    Activity.LoadLayout("1")
       ctxt.InitializeContext
     
    End Sub

    'Possible values: DEFAULT, HOME_SCREEN, STARTUP, PAUSE, EXIT, LEVEL_START, LEVEL_COMPLETE, ACHIEVEMENTS, LEADERBOARDS, STORE
    Sub CreateAd (AdUnitId As StringAs JavaObject
       
    Dim AdId As JavaObject
       AdId.InitializeStatic(
    "com.appbrain.AdId")
       
    Dim builder As JavaObject
       builder = builder.InitializeStatic(
    "com.appbrain.InterstitialBuilder").RunMethod("create"Null)
       builder.RunMethod(
    "setAdId"Array(AdId.GetField(AdUnitId)))
       
    Dim listener As Object = builder.CreateEventFromUI("com.appbrain.InterstitialListener""listener"Null)
       builder.RunMethod(
    "setListener"Array(listener))
       builder.RunMethod(
    "preload"Array(ctxt))
       
    Return builder
    End Sub

    Sub Listener_Event (MethodName As String, Args() As Object) As Object
       
    If Args <> Null Then
           
    Dim largs As List = Args
           
    Log(MethodName & ": " & largs)
       
    Else
           
    Log(MethodName)
       
    End If
       
    Return Null
    End Sub

    Sub Activity_Resume
       ad = CreateAd(
    "DEFAULT")
    End Sub

    Sub Activity_Click
       ad.RunMethod(
    "show"Array(ctxt)) 'show it
    End Sub
    Depends on: JavaObject
     
    Last edited: Jun 17, 2018
    Toky Olivier, HAH, tuhatinhvn and 6 others like this.
  2. Filippo

    Filippo Expert Licensed User

    Hi,

    kann mir jemand sagen warum ich bekomme diese Fehlermeldung bekomme?
    can someone tell me why i get this error message?

    The AAR-file "appbrain-sdk-14.10.aar" is in the additional libraries folder.
     
    Last edited: Jun 15, 2018
  3. Alexander Stolte

    Alexander Stolte Well-Known Member Licensed User

    wrong text copied from google translate? :D
     
    Filippo likes this.
  4. Filippo

    Filippo Expert Licensed User

    Ja, Yes :p
     
    Alexander Stolte likes this.
  5. DonManfred

    DonManfred Expert Licensed User

    Google Translate ist hier sogar besseres Deutsch als das Original :D

    Googles translation is, in this case, better than the Original :D
     
    Last edited: Jun 15, 2018
    Filippo likes this.
  6. Filippo

    Filippo Expert Licensed User

    :mad:


    please write here only in English! :p
     
  7. DonManfred

    DonManfred Expert Licensed User

    You are right. I added english to the Post above :)
     
  8. amidgeha

    amidgeha Member Licensed User

    You must follow Erel's instructions, the additionaljar must be like this:
    #AdditionalJar: appbrain-sdk-14.10.aar
    don't use double quotes and you'll be ok.
     
    Last edited: Jun 15, 2018
    Erel and Filippo like this.
  9. Filippo

    Filippo Expert Licensed User

    Thanks, that was the missing step. :)
     
  10. Erel

    Erel Administrator Staff Member Licensed User

    I've updated the instructions.
     
  11. Feten7

    Feten7 Member Licensed User

    I have a question: I have created several banners in appbrain's web and, thanks to amidgeha and Erel, i can show a banner. Now, I'd want to show each of them in a different activity. How can I set the ID of the banner i want to use?
     
  12. Alexander Stolte

    Alexander Stolte Well-Known Member Licensed User

    Please start a new thread, for this question :)
     
Loading...
  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