Android Question How to use b4a code to initialize AAR class with listener parameter

Maodge

Member
Licensed User
Hi all,
I'm trying to use the tencentad sdk and I'm having some difficulties.
the problem is how to using b4a code to initialize AAR class with listener parameter

here is sdk demo java code SplashActivity.java

And I have init sdk,and test it is initial OK.
B4X:
Sub InitialGDTADManager
    'ref java code:
    'GDTADManager.getInstance().initWith(applicationContext, "APPID");
  
    If Flag_GDTADManager_Initial = False Then
        Log("GDTADManager Init")
        GDTADManager = GDTADManager.InitializeStatic("com.qq.e.comm.managers.GDTADManager").RunMethod("getInstance",Null)
        GDTADManager.RunMethod("initWith",Array(NativeMe,"1101152570")) '1101152570 demo appid
        Flag_GDTADManager_Initial = True
    End If
  
    Dim flag As Boolean = False
    flag = GDTADManager.RunMethod("isInitialized",Null)
    Log("GDTADManager Init : "&flag)
End Sub

Next I need initial SplashAD. here I'm in trouble, because splash initial function need a panel and a listener as its parameter.
I have been looking for a long time in the forum, and there is no similar code for my reference.
Can anyone help me? Any help is welcome. Thanks.

B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.

    Private SplashAD As JavaObject
    Private SplashADListener As JavaObject
end sub

B4X:
Sub Initial_Load_Splash
      
    'SplashAD(Activity activity, View skipContainer, String posId, SplashADListener adListener, int fetchDelay)
    'ref java code:
    'splashAD = new SplashAD(activity, skipContainer, posId, adListener, fetchDelay);
  
    'Splash : com.qq.e.ads.splash.SplashAD
    'SplashADListener : com.qq.e.ads.splash.SplashADListener
    'activity : B4A main activity
    'skipContainer : B4A pnl_skip
    'posId : "8863364436303842593" demo splash id
    'fetchDelay : 0
    
    SplashADListener.InitializeStatic("com.qq.e.ads.splash.SplashADListener")
    
    SplashAD.InitializeNewInstance("com.qq.e.ads.splash.SplashAD",Array(Activity,pnl_skip,"8863364436303842593",SplashADListener,0)) '---ERR
    
    
End Sub

ERR MESSAGE:
Error occurred on line: 220 (Main)
java.lang.RuntimeException: Constructor not found.
at anywheresoftware.b4j.object.JavaObject.InitializeNewInstance(JavaObject.java:95)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:777)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:354)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:197)
at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:262)
at com.qq.e.union.demo.main._initial_load_splash(main.java:622)
at com.qq.e.union.demo.main$ResumableSub_Activity_Create.resume(main.java:557)
at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resumeAsUserSub(DebugResumableSub.java:48)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:197)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resume(DebugResumableSub.java:43)
at anywheresoftware.b4a.keywords.Common$13.run(Common.java:1704)
at android.os.Handler.handleCallback(Handler.java:809)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:166)
at android.app.ActivityThread.main(ActivityThread.java:7555)
 

Attachments

  • SplashActivity.java
    15.3 KB · Views: 326
  • TEST_USING_QQAD.zip
    47.3 KB · Views: 195
  • classes.jar
    207.7 KB · Views: 179
Last edited:

Maodge

Member
Licensed User
AAR is the package. It doesn't matter whether it is a Jar, inline code or AAR.

If the listener is an interface then you can create it with JavaObject.CreateEventFromUI.

There are many example: https://www.b4x.com/android/forum/pages/results/?query=CreateEventFromUI

Thanks Erel.

I read some code about CreateEventFromUI from forum. and try program
B4X:
SplashAD.InitializeNewInstance("com.qq.e.ads.splash.SplashAD", Array(Activity, pnl_skip, "8863364436303842593", Activity, 0)) <-- error
        
    SplashADListener = SplashAD.CreateEventFromUI("com.qq.e.ads.splash.SplashADListener","SplshAD1",Null)

I got some err message:
java.lang.RuntimeException: Constructor not found.

but in classes.jar under splash - SplashAD.class - SplashAD, the function SplashAD(Context, View, String, SplashADListener, int) found.

and i read SplashActivity.java file, demo code of init splashad is
Java:
fetchSplashAD(this, container, skipView, getPosId(), this, 0);
and fetchSplashAD code is
Java:
Private void fetchSplashAD(Activity Activity, ViewGroup adContainer, View skipContainer,
        String posId, SplashADListener adListener, int fetchDelay) {
        fetchSplashADTime = System.currentTimeMillis();
        SplashAD = new SplashAD(Activity, skipContainer, posId, adListener, fetchDelay);
        If(loadAdOnly) {
            SplashAD.fetchAdOnly();
        }else{
            SplashAD.fetchAndShowIn(adContainer);
           }
      }

compare splashad parameter
SplashAD(Activity activity, View skipContainer, String posId, SplashADListener adListener, int fetchDelay)

I do not know how to solove it.
I have no experience in Java, nor in how to make use of aar using direct calls to Java.

Can you give me an example where it can be seen clearly how to do this?

Thanks.
 
Upvote 0
Top