B4A Library Tappx ads service

1. Register with Tappx and get an app key: https://www.tappx.com

2. Download their AAR library and copy it to the additional libraries folder: https://repo1.maven.org/maven2/com/tappx/sdk/android/tappx-sdk/3.1.3/

3. Add dependencies:
B4X:
#AdditionalJar: tappx-sdk-3.0.9.aar
#AdditionalJar: com.google.android.gms:play-services-ads

4. Add to manifest editor:
B4X:
CreateResourceFromFile(Macro, FirebaseAnalytics.GooglePlayBase)
AddPermission(android.permission.INTERNET)
AddPermission(android.permission.ACCESS_NETWORK_STATE)
AddApplicationText(
<!-- Tappx Activities -->
<activity
    android:name="com.tappx.sdk.android.AdActivity"
    android:configChanges="keyboardHidden|orientation|screenSize" />
<activity
    android:name="com.tappx.sdk.android.InterstitialAdActivity"
    android:configChanges="keyboardHidden|orientation|screenSize"
    android:theme="@style/Transparent" />
<activity
    android:name="com.tappx.sdk.android.VideoAdActivity"
    android:configChanges="keyboardHidden|orientation|screenSize" />

<service android:name="com.tappx.sdk.android.TrackInstallIntentService" />

<!-- AdActivity from Google Play Services,, needed by Tappx -->
<activity
    android:name="com.google.android.gms.ads.AdActivity"
            android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
    android:theme="@android:style/Theme.Translucent" />
)
Replace CreateResourceFromFile(Macro, FirebaseAnalytics.GooglePlayBase) with the snippet from firebase integration tutorial if using an older version of B4A.

5. Code, make sure to update the key:
B4X:
Sub Globals
   Private const TappxKey As String = "Pub-8888-Android-6456"
   Private banner As JavaObject
End Sub

Sub Activity_Create(FirstTime As Boolean)
   CreateBanner(TappxKey)
   Activity.AddView(banner, 0, 0, 320dip, 50dip)
End Sub

Sub CreateBanner (key As String)
   Dim banner As JavaObject
   Dim ctxt As JavaObject
   ctxt.InitializeContext
   banner.InitializeNewInstance("com.tappx.sdk.android.TappxBanner", Array(ctxt, key))
   banner.RunMethod("setAdSize", Array("BANNER_320x50"))
   banner.RunMethod("loadAd", Null)
   Dim listener As Object = banner.CreateEventFromUI("com.tappx.sdk.android.TappxBannerListener", "ad", Null)
   banner.RunMethod("setListener",Array(listener))
End Sub

Sub Ad_Event (MethodName As String, Args() As Object) As Object
   Dim argsList As List = Args
   Log(MethodName & ": " & argsList)
   Return Null
End Sub

Sub Activity_Pause (UserClosed As Boolean)
   If UserClosed Then
       If banner.IsInitialized Then
           banner.RunMethod("destroy", Null)
       End If
   End If
End Sub

Depends on JavaObject.
 
Last edited:

mlc

Active Member
Licensed User
Longtime User
Thanks Erel.
Very interesting to promote your app for free.
I have already uploaded an app with his sdk, today is the first day and in just a few hours I had 1018 impressions of my app for free.

Here I leave my "Guess-Link", https://www.tappx.com/?h=24b49ecbf874669c8f1ea5c067b98c28
For every member that integrates his app after registering from my "Guess-Link" I will win extra promotion. 50000 tappix.
 

sorex

Expert
Licensed User
Longtime User
To make this comply with the EU GDPR misery we need to use the current SDK and some additional likes of code.

But I'm having problems to convert the code to something working.
(full example code can be found here > https://www.tappx.com/en/manual/?os=and#1_integration_gdpr)

while the main aim is to use only the lines below based on the setting they select in my privacy policy page

B4X:
Tappx.getPrivacyManager(context).grantPersonalInfoConsent();

Tappx.getPrivacyManager(context).denyPersonalInfoConsent();

I currently try to just display their own disclaimer so that I know that the privacy manager is working.

B4X:
Tappx.getPrivacyManager(context).checkAndShowPrivacyDisclaimer(activity);
looking at the .arr file there's a TappxPrivacyManager class.

So I assumed this should be the code

B4X:
Dim consentGDPR As JavaObject
Dim ctxtGDPR As JavaObject
ctxtGDPR.InitializeContext
consentGDPR.InitializeNewInstance("com.tappx.sdk.android.TappxPrivacyManager", Array(ctxtGDPR, Null))
consentGDPR.RunMethod("checkAndShowPrivacyDisclaimer", Null)

but this gives java.lang.RuntimeException: Constructor not found. on the initializeNewInstance line.

Can any javaObject expert give some advice on how to make this code working?
 

sorex

Expert
Licensed User
Longtime User
Thanks, Erel.

No errors with that method.

But when I add the following line

B4X:
PrivacyManager.RunMethod("checkAndShowPrivacyDisclaimer", Array(ctxt))

nothing shows up BUT no ads are loaded either so I guess it's waiting for that consent grant/deny value.
(their documentation mentioned that it ignores request untill the consent mode was selected)

commenting that line and then using

B4X:
PrivacyManager.RunMethod("grantPersonalInfoConsent", Null)

makes the ads load again so I guess that's the way it's supposed to work.
 

chris ash

Member
Licensed User
Longtime User
Hi @sorex

I have been reading this one with interest. Would you have a sample project that you could supply that has the basics of getting the adverts working with the GDPR requirements in place?

I have had a go and managed to get some adverts but I am just a little unsure what I need to put and where.

Thanks in advance for any assistance

Kind Regards
CAsh
 

Douglas Farias

Expert
Licensed User
Longtime User
hi @Erel.
thx for the example.
can you make a sample code, of how add a intersticial with events? closed, ready etc...?

thank you
 

sorex

Expert
Licensed User
Longtime User
you can use the event callback for that.

altho it makes more sense to do the load on a button press (go on with next level for example)

B4X:
Sub tappxInterstitial_Event (MethodName As String, Args() As Object) As Object
    Select MethodName
        Case "onInterstitialShown"
            tappxInterstitialLoad
     End Select
Return Null
End Sub
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Try this:
B4X:
Sub CreateIAd (key As String)
   Dim iad As JavaObject
   Dim ctxt As JavaObject
   ctxt.InitializeContext
   iad.InitializeNewInstance("com.tappx.sdk.android.TappxInterstitial", Array(ctxt, key))
   iad.RunMethod("setAutoShowWhenReady", Array(True))
   iad.RunMethod("loadAd", Null)
   Dim listener As Object = iad.CreateEventFromUI("com.tappx.sdk.android.TappxInterstitialListener", "iad", Null)
   iad.RunMethod("setListener",Array(listener))
End Sub

Sub IAd_Event (MethodName As String, Args() As Object) As Object
   Dim argsList As List = Args
   Log(MethodName & ": " & argsList)
   Return Null
End Sub
 

Douglas Farias

Expert
Licensed User
Longtime User
Hello everyone.
Complementing the Erel example, below is an example using the latest SDK version (3.1.9) and also using Interstitial.

Download the 3.1.9 arr file.
B4X:
#AdditionalJar: tappx-sdk-3.1.9.aar
#AdditionalJar: com.google.android.gms:play-services-ads

Manifest
XML:
'TAPPX
CreateResourceFromFile(Macro, FirebaseAnalytics.GooglePlayBase)
AddPermission(android.permission.INTERNET)
AddPermission(android.permission.ACCESS_NETWORK_STATE)
AddPermission(android.permission.ACCESS_COARSE_LOCATION)
AddApplicationText(
<activity
    android:name="com.tappx.sdk.android.AdActivity"
    android:configChanges="keyboardHidden|orientation|screenSize" />
<activity
    android:name="com.tappx.sdk.android.InterstitialAdActivity"
    android:configChanges="keyboardHidden|orientation|screenSize"
    android:theme="@style/Transparent" />
<activity
    android:name="com.tappx.sdk.android.VideoAdActivity"
    android:configChanges="keyboardHidden|orientation|screenSize" />
<service android:name="com.tappx.sdk.android.TrackInstallIntentService" />
<activity
    android:name="com.google.android.gms.ads.AdActivity"
            android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
    android:theme="@android:style/Theme.Translucent" />
<receiver
        android:name="com.tappx.sdk.android.TrackInstallReceiver"
        android:exported="true">
    <intent-filter>
        <action android:name="com.android.vending.INSTALL_REFERRER"/>
    </intent-filter>
</receiver>
)

Service
B4X:
#Region  Service Attributes
    #StartAtBoot: False
#End Region

Sub Process_Globals

    'GENERAL
    Private appKey As String = "pub-xxxxx-android-xxxx"
    Private retryTime As Int = 30000
    Private reloadTime As Int = 2000
    Private ctxt As JavaObject

    'INTER
    Private tappxIntersticial As JavaObject
    Private interListener As Object
    Public isInterstitialReady As Boolean = False

    'BANNER
    Private bannerListener As Object
    Public bannerView As JavaObject
    Public isBannerReady As Boolean = False

End Sub

Sub Service_Create

    'INITIALIZE CONTEXT
    ctxt.InitializeContext


    'BANNER
    bannerView.InitializeNewInstance("com.tappx.sdk.android.TappxBanner", Array(ctxt,appKey))
    bannerView.RunMethod("setAdSize", Array("BANNER_320x50"))
    bannerListener = bannerView.CreateEventFromUI("com.tappx.sdk.android.TappxBannerListener", "TappxBanner", Null)
    bannerView.RunMethod("setListener",Array(bannerListener))
    Load_Banner

    'INTER
    tappxIntersticial.InitializeNewInstance("com.tappx.sdk.android.TappxInterstitial", Array(ctxt, appKey))
    interListener = tappxIntersticial.CreateEventFromUI("com.tappx.sdk.android.TappxInterstitialListener", "TappxIntersticial", Null)
    tappxIntersticial.RunMethod("setListener",Array(interListener))


    Load_Inter


End Sub

Sub Service_Start (StartingIntent As Intent)
    Service.StopAutomaticForeground
End Sub

Sub Service_Destroy
    bannerView.RunMethod("destroy", Null)
    tappxIntersticial.RunMethod("destroy", Null)
End Sub




#Region INTERSTICIAL

Sub Load_Inter
    tappxIntersticial.RunMethod("loadAd", Null)
End Sub

Sub TappxIntersticial_Event (MethodName As String, Args() As Object) As Object 'EVENTOS DO INTERSTICIAL
    Select MethodName

        Case "onInterstitialLoaded"
            LogColor("onInterstitialLoaded Inter Tappx", Colors.Red)
            isInterstitialReady = True
    
        Case "onInterstitialLoadFailed"
            LogColor("onInterstitialLoadFailed Inter Tappx", Colors.Red)
            isInterstitialReady = False
            Retry_Inter
    
        Case "onInterstitialShown"
            LogColor("onInterstitialShown Inter Tappx", Colors.Red)
            isInterstitialReady = False
    
        Case "onInterstitialClicked"
            LogColor("onInterstitialClicked Inter Tappx", Colors.Red)
            isInterstitialReady = False
    
        Case "onInterstitialDismissed"
            LogColor("onInterstitialDismissed Inter Tappx", Colors.Red)
            isInterstitialReady = False
            Reload_Inter
        
    End Select
    Return Null
End Sub


Sub Show_Inter
    tappxIntersticial.RunMethod("show", Null)
End Sub


Sub Retry_Inter
    isInterstitialReady = False
    Sleep(retryTime)
    Load_Inter
End Sub

Sub Reload_Inter
    isInterstitialReady = False
    Sleep(reloadTime)
    Load_Inter
End Sub


#End Region




#Region BANNER

Sub Load_Banner
    bannerView.RunMethod("loadAd", Null)
End Sub

Sub TappxBanner_Event (MethodName As String, Args() As Object) As Object 'EVENTOS DO BANNER
    Select MethodName

        Case "onBannerLoaded"
            LogColor("onBannerLoaded Banner Tappx", Colors.Red)
            isBannerReady = True
    
        Case "onBannerLoadFailed"
            LogColor("onBannerLoadFailed Banner Tappx", Colors.Red)
            isBannerReady = False
            Retry_Banner
    
        Case "onBannerClicked"
            LogColor("onBannerClicked Banner Tappx", Colors.Red)
            isBannerReady = False
    
        Case "onBannerExpanded"
            LogColor("onBannerExpanded Banner Tappx", Colors.Red)
    
        Case "onBannerCollapsed"
            LogColor("onBannerCollapsed Banner Tappx", Colors.Red)
            isBannerReady = False
        
    End Select
    Return Null
End Sub

Sub Retry_Banner
    isBannerReady = False
    Sleep(retryTime)
    Load_Banner
End Sub

#End Region
I use it in a service (where all events work correctly), but you can compile it as a library or use it as a class.

Interstitial
B4X:
If Not(IsPaused(Tappx)) And Tappx.isInterstitialReady Then CallSub(Tappx, "Show_Inter")

Banner
B4X:
If Not(IsPaused(Tappx)) And Tappx.isBannerReady Then
    Private bannerView As View
    bannerView = Tappx.bannerView
    Activity.AddView(bannerView,0%x, 100%y - 51dip, 100%x, 51dip)
End if


Thx
 
Last edited:
Top