[Library] Samsung AdHub

XverhelstX

Well-Known Member
Licensed User
Longtime User
Hello Everyone,

Samsung Adhub is another way of monetizing your apps.
It features Banner ads and Interstitial ads.

Different from other ad networks is that with Samsung AdHub, you are able to set the interests of users to suit your app with a so called UserProfile.
This way you can display ads which are related to the user's age, gender, interests, etc.

The library is very easy to use and implement in your app!

A sample is delivered which explains everything in detail which i copied below.

B4X:
'Activity module
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
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.
   
   'Declaration of the ads.
   Dim adBanner As AdHubBanner
   Dim adSize As AdHubSize
   Dim adInterstitial As AdHubInterstitial
   Dim adProfile As AdHubUserProfile
End Sub

Sub Activity_Create(FirstTime As Boolean)
   'Loads the Activity stuff
   Activity.loadlayout("Main.bal")
   Activity.AddMenuItem("Show Ad Banner","mnuBanner")
   Activity.AddMenuItem("Show Ad Interstitial","mnuInterstitial")
   
   'Initializes the AdHub Banner.
   '1th Param: EventName
   '2nd Param: Id from Samsung Adhub - The current one is for development stage!
   '3th Param: Banner Size
   '4th Param: Set Listener?
   adBanner.Initialize("Banner", "2011000001_001", adSize.Banner, True)
   
   'Initializes the AdHub Interstitial.
   '1th Param: EventName
   '2nd Param: Id from Samsung Adhub - The current one is for development stage!
   '3th Param: Set Listener?
   adInterstitial.Initialize("Interstitial", "2011000001_001", False)
   
   'Initialize AdHub Profile
   'This is used to determine who the adviewer is: intrests, age, gender, etc.
   adProfile.Initialize
   adProfile.Age = 18
   adProfile.Gender = "m"
   adProfile.Interests = "Programming"
   adProfile.Interests = "Basic4Android"
   adProfile.Interests = "Samsung Galaxy"
   
   'Then you can attach it to one of the ads.
   adBanner.UserProfile = adProfile.UserProfile
   
   'Sets a listener - --- Only do this when the last parameter in the Initialize method is false! ---
   'adBanner.setAdListener '- Not needed because we set it to true in initialize.
   'Doesn't count for Interstitial because it is false in initialize.
   adInterstitial.setAdListener

   
   'Add the AdHub Banner to the Activity
   Activity.AddView(adBanner, 0dip, 0dip, 320dip, 48dip)
   
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

'Shows an AdHub ad banner when clicked.
Sub mnuBanner_Click

   'Starts an AdHub banner.
   adBanner.startAd

End Sub

'Show an AdHub Interstitial ad when clicked
Sub mnuInterstitial_Click
   
   'Shows an AdHub Interstitial ad.
   adInterstitial.startAd

End Sub

' ---- !Adhub Banner Ads Events! ---- '
Sub Banner_OnAdFailed (Message As String)
   Log("Error AdHub Banner: " & Message)

End Sub

Sub Banner_OnAdReceived
   Log("AdHub Banner received!")

End Sub

' ---- !Adhub Interstitial Ads Events! ---- '
Sub Interstitial_OnAdFailed (Message As String)
   Log("Error: " & Message)

End Sub

Sub Interstitial_OnAdReceived
   Log("AdHub Interstitial Ad received!")

End Sub

Sub Interstitial_onAdInterstitialClosed
   Log("Adhub Interstitial Ad Closed.")
End Sub

Also don't forget to add the following to the manifest file!

B4X:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: http://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="4" />
<supports-screens android:largeScreens="true" 
    android:normalScreens="true" 
    android:smallScreens="true" 
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")


'End of default text.

'Banner ads - AdHub
SetApplicationAttribute(android:configChanges, "keyboardHidden|orientation")

'Interstitial ads - AdHub
AddApplicationText(
   <activity 
      android:name="com.sec.android.ad.AdActivity"     
      android:configChanges="keyboardHidden|orientation" /> )

However I haven't been able to display an interstitial ad yet. Perhaps you need an Active InventoryID to test Interstitial ads out instead of a development one because i'm sure my code is correct.

As last!

Don't forget to register to Samsung AdHub when releasing your application.
You'll need to fill in some regular stuff, create your appform and retrieve your inventory id.
Don't forget to change your test inventoryID with your actual one!
http://www.samsungadhub.com/main.do

In the attachments, you can find:
- Documentation: (Javadoc, Readme)
- Sample file
- Library files

Have fun!
Tomas
 

Attachments

  • Libraries.zip
    186.7 KB · Views: 554
  • AdHubSample.zip
    3 KB · Views: 484
  • Doc.zip
    52.3 KB · Views: 476
Last edited:

barx

Well-Known Member
Licensed User
Longtime User
Thanks for this XverhelstX. A very good contribution to the ads libraries available for b4a.
 

NFOBoy

Active Member
Licensed User
Longtime User
New SDK breaks the library?

So downloaded the new SDK : SamsungAdHub_AndroidSDK_V2.5.2.zip, which was released on the 5th of February.

I put it in the library folder and renamed to SamsungAdHub.jar, (overwriting the old SDK).

Now when I try and run, I get this:

B4X:
** Activity (main) Create, isFirst = true **


RSAdHubInitialize (java line: 45)


java.lang.ClassCastException: android.app.Application
   at com.ormma.view.OrmmaView.<init>(OrmmaView.java:188)
   at com.sec.android.ad.container.AdExpandable.<init>(AdExpandable.java:33)
   at com.sec.android.ad.AdHubView.initExpandable(AdHubView.java:443)
   at com.sec.android.ad.AdHubView.init(AdHubView.java:283)
   at com.rootsoft.adhub.RSAdHub.Initialize(RSAdHub.java:45)
   at com.rootsoft.adhub.main._activity_create(main.java:238)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:507)
   at anywheresoftware.b4a.BA.raiseEvent2(BA.java:165)
   at com.rootsoft.adhub.main.afterFirstLayout(main.java:84)
   at com.rootsoft.adhub.main.access$100(main.java:16)
   at com.rootsoft.adhub.main$WaitForLayout.run(main.java:72)
   at android.os.Handler.handleCallback(Handler.java:587)
   at android.os.Handler.dispatchMessage(Handler.java:92)
   at android.os.Looper.loop(Looper.java:130)
   at android.app.ActivityThread.main(ActivityThread.java:3687)


   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:507)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
   at dalvik.system.NativeStart.main(Native Method)
java.lang.ClassCastException: android.app.Application

This looks like a nice update to their SDK, as it removes two permissions: - Deleted essential Permission (SEND_SMS, READ_CALENDAR)
- Modified previous interstitial house ad error


Does the possibility exist to update this library?

Thanks!

Ross
 
Top