B4A Library AppBrain Ads

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:
B4X:
'**************  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:
B4X:
#AdditionalJar: appbrain-sdk-14.10.aar
5. Code to create an interstitial ad:
B4X:
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 String) As 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:
D

Deleted member 103

Guest
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.
B4A Version: 8.00
Parsing code. (0.13s)
Compiling code. (1.67s)
Compiling layouts code. (0.10s)
Organizing libraries. (4.28s)
Generating R file. Error
AndroidManifest.xml:132: error: Error: No resource found that matches the given name (at 'enabled' with value '@bool/appbrain_job_service_enabled').
 
Last edited by a moderator:

DonManfred

Expert
Licensed User
Longtime User
kann mir jemand sagen warum ich bekomme diese Fehlermeldung bekomme?
can someone tell me why i get this error message?
Google Translate ist hier sogar besseres Deutsch als das Original :D

Googles translation is, in this case, better than the Original :D
 
Last edited:

amidgeha

Active Member
Licensed User
Longtime 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.

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:
D

Deleted member 103

Guest
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.
Thanks, that was the missing step. :)
 

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?
 

Alexander Stolte

Expert
Licensed User
Longtime 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?
Please start a new thread, for this question :)
 
Top