Android Question AdColony advertising library

Erel

B4X founder
Staff member
Licensed User
Longtime User
Start with this:
B4X:
#AdditionalJar: adcolony
#AdditionalJar: androidx.appcompat:appcompat
#AdditionalJar: com.google.android.gms:play-services-ads-identifier
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    Private AdColony As JavaObject
End Sub

Sub Activity_Create(FirstTime As Boolean)
    AdColony.InitializeStatic("com.adcolony.sdk.AdColony")
    Dim ctxt As JavaObject
    ctxt.InitializeContext
    AdColony.RunMethod("configure", Array(ctxt, "app id", Array As String("zone id"))) '<----------
    RequestInterstitial
End Sub

Sub RequestInterstitial
    Dim listener As JavaObject
    listener.InitializeNewInstance(Application.PackageName & ".main$MyAdColonyInterstitialListener", Null)
    AdColony.RunMethod("requestInterstitial", Array("zone id", listener)) '<----------
End Sub

Sub AdColony_OnRequestFilled (Ad As Object)
    Log("OnRequestFilled")
    Log(Ad)
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

#if Java
import com.adcolony.sdk.*;
public static class MyAdColonyInterstitialListener extends AdColonyInterstitialListener {
    public void onRequestFilled(AdColonyInterstitial ad) {
        main.processBA.raiseEventFromUI(null, "adcolony_onrequestfilled", ad);
    }
}
#End If

Manifest:
B4X:
CreateResourceFromFile(Macro, Core.NetworkClearText)
AddPermission(android.permission.INTERNET)
AddPermission(android.permission.ACCESS_NETWORK_STATE)
AddApplicationText(<activity android:name="com.adcolony.sdk.AdColonyInterstitialActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
android:hardwareAccelerated="true"/>
<activity android:name="com.adcolony.sdk.AdColonyAdViewActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
android:hardwareAccelerated="true"/>)
CreateResourceFromFile(Macro, FirebaseAnalytics.GooglePlayBase)

Download adcolony.jar: https://github.com/AdColony/AdColony-Android-SDK/blob/master/Library/adcolony.jar

I don't have an app id and zone id so cannot fully test it.

If you see OnRequestFilled in the logs then we can progress.
 
Upvote 0

SMOOTSARA

Active Member
Licensed User
Longtime User

Thank you Erel
I have followed your instructions and will post the result below


B4X:
#Region  Project Attributes
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName: 1.0.0
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
    
#AdditionalJar: adcolony
#AdditionalJar: androidx.appcompat:appcompat
#AdditionalJar: com.google.android.gms:play-services-ads-identifier
#End Region

Sub Process_Globals
    
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Private AdColony As JavaObject
    
    

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    
    
    Dim appid As String =     "app6e40d81b1cc84c4891"
    Dim zoneid As String =     "vz6c2d7e01d0f849cf9e"
    
    Dim Button1 As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    Log("start")
    Activity.Color=Colors.Red
    
    AdColony.InitializeStatic("com.adcolony.sdk.AdColony")
    Dim ctxt As JavaObject
    ctxt.InitializeContext
    AdColony.RunMethod("configure", Array(ctxt, appid, Array As String(zoneid))) '<----------
    
    Button1.Initialize("Button1")
    Activity.AddView(Button1,10%x,50%y,80%x,12%y)
    


End Sub

Sub Button1_Click
    RequestInterstitial
End Sub

Sub RequestInterstitial
    Dim listener As JavaObject
    listener.InitializeNewInstance(Application.PackageName & ".main$MyAdColonyInterstitialListener", Null)
    AdColony.RunMethod("requestInterstitial", Array(zoneid, listener)) '<----------
End Sub



Sub AdColony_OnRequestFilled (Ad As Object)
    Log("OnRequestFilled")
    Log(Ad)
    
End Sub




Sub Activity_Resume

End Sub



Sub Activity_Pause (UserClosed As Boolean)

End Sub


#if Java
import com.adcolony.sdk.*;
public static class MyAdColonyInterstitialListener extends AdColonyInterstitialListener {
    public void onRequestFilled(AdColonyInterstitial ad) {
        main.processBA.raiseEventFromUI(null, "adcolony_onrequestfilled", ad);
    }
}
#End If



"Adcolony" ads are set to test so we have to see the ads display. But the error is returned in Logs.


B4X:
Logger connected to:  asus ASUS_X00LD
--------- beginning of main
** Activity (main) Pause, UserClosed = false **
** Service (starter) Destroy (ignored)**
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
start
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = true **
** Service (starter) Destroy (ignored)**
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
start
** Activity (main) Resume **
OnRequestFilled
com.adcolony.sdk.AdColonyInterstitial@e453ed3
OnRequestFilled
com.adcolony.sdk.AdColonyInterstitial@d72ef7d
OnRequestFilled
com.adcolony.sdk.AdColonyInterstitial@972976c
OnRequestFilled
com.adcolony.sdk.AdColonyInterstitial@25e5c17
OnRequestFilled
com.adcolony.sdk.AdColonyInterstitial@23a46e
OnRequestFilled
com.adcolony.sdk.AdColonyInterstitial@2754321
OnRequestFilled
com.adcolony.sdk.AdColonyInterstitial@9065a0
OnRequestFilled
com.adcolony.sdk.AdColonyInterstitial@c923f1b
OnRequestFilled
com.adcolony.sdk.AdColonyInterstitial@1955f82
OnRequestFilled
com.adcolony.sdk.AdColonyInterstitial@9962ffc
OnRequestFilled
com.adcolony.sdk.AdColonyInterstitial@ac3902c
OnRequestFilled
com.adcolony.sdk.AdColonyInterstitial@95977d7
OnRequestFilled
com.adcolony.sdk.AdColonyInterstitial@bca6f2e
OnRequestFilled
com.adcolony.sdk.AdColonyInterstitial@a3378e1
** Activity (main) Pause, UserClosed = false **


Question 1: What's the problem?
Question 2: How the advertising display method is implemented

Thank you
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
now you need to call the routine to display it
right. @Erel wrote
If you see OnRequestFilled in the logs then we can progress.

You can try this untested Code (note i´m not so good in JavaObject!)

B4X:
Sub AdColony_OnRequestFilled (Ad As Object)
    Log("OnRequestFilled")
    Log(Ad)
    dim addColony As JavaObject = Ad
    addColony.RunMethod("show", Array()))

End Sub
 
Last edited:
Upvote 0

SMOOTSARA

Active Member
Licensed User
Longtime User


Thank you @DonManfred

Fullscreen ads displayed
thank you


?
 
Upvote 0

SMOOTSARA

Active Member
Licensed User
Longtime User
You can pass Null if there are no parameters:
B4X:
dim adColony As JavaObject = Ad
    adColony.RunMethod("show", Null)



Thank you @Erel
The ads were displayed well.

How can other methods of this library be used?
For example, show banner ads and video ad Or get click methods
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Untested code:
B4X:
Sub RequestAdView
   Dim size As JavaObject
   size = size.InitializeStatic("com.adcolony.sdk.AdColonyAdSize").GetField("BANNER") '320dip x 50dip
    Dim listener As JavaObject
    listener.InitializeNewInstance(Application.PackageName & ".main$MyAdColonyAdViewListener", Null)
    AdColony.RunMethod("requestAdView", Array(zoneid, listener, size)) '<----------
End Sub

Sub AdColony_AdView_OnRequestFilled (Ad As Object)
 
    Log("AdColony_AdView_OnRequestFilled ")
    Log(Ad)
    Dim v As View = ad
    Activity.AddView(v, 0, 0, 320dip, 50dip)
End Sub


#if Java
import com.adcolony.sdk.*;
public static class MyAdColonyAdViewListener extends AdColonyAdViewListener{
public void onRequestFilled(AdColonyAdView adview) {
main.processBA.raiseEventFromUI(null, "adcolony_adview_onrequestfilled", adview);
}
}
#End If
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
The code is not too complicated. You should be able to add other events yourself.

For example:
B4X:
#if Java
import com.adcolony.sdk.*;
public static class MyAdColonyAdViewListener extends AdColonyAdViewListener{
public void onRequestFilled(AdColonyAdView adview) {
main.processBA.raiseEventFromUI(null, "adcolony_adview_onrequestfilled", adview);
}
public void onClicked(AdColonyAdView adview) {
main.processBA.raiseEventFromUI(null, "adcolony_adview_onclicked", adview);
}

}
#End If
 
Upvote 0

SMOOTSARA

Active Member
Licensed User
Longtime User


Hi @Erel
Thank you for your response
The codes are not working properly!
I want to provide a complete resource with all classes and methods for this ad service to make it a library
What resources should I use to know the methods and classes of this library?
Thank you
 
Upvote 0

SMOOTSARA

Active Member
Licensed User
Longtime User
i did found the show method using their site and followed the links on their site.
Do not remember exactly where.


We cannot help you with this information...


Hi

Thanks for your attention?

These are the classes in this library:
and

You may guide me on how to use these classes in my program
A simple example will help a lot.?
Thank you
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…