Android Question WebViewExtras2 AddJavascriptInterface, CallSub no return value to jscript

pertov

Member
Dear All;
B4X:
WebViewExtras1.AddJavascriptInterface(jsi,"BB")
...
Sub md5(str As String) As String
    Dim j As JavaObject
    j.InitializeContext
    Dim s As String
    s = j.RunMethod("getMD5",Array(str))
    s=s.ToUpperCase
    Log("return>>>"&s)
    Return s
End Sub

Sub lg(s As String)
    LogColor(s,Colors.Magenta)
End Sub
JavaScript:
function nt(){
   
    BB.CallSub("lg",false,"before md5");
    var s;
    s=BB.CallSub("md5",false,"1");
    mss.innerText ="и md5="+ s;
    BB.CallSub("lg",false,"after md5 =" + s);
    //alert("1="+s);
}

i'am run javascipt.nt() function + view log window:
1741954736043.png

I'm waiting for the result in the function as shown in the screenshot, but it's = undefined.
What am I doing wrong?
 

drgottjr

Expert
Licensed User
Longtime User
i answered a similar question almost 3 years ago to the date. you should have searched. download the example in post #4 and compare it with yours. i don't think you set up your code correctly. just pay attention to how the javascript interface is set up in webviewextras2. it's not the same as for webviewetras. just the javascript interface. the rest is not applicable.
 
Upvote 0

pertov

Member
....... i don't think you set up your code correctly. ....
hi,
in your example (link), there is no java to javascript value return.

calls without returning results from java to jscript =work in any [debug|release] mode

release mode=
1742208728520.png

debug mode=
1742208749986.png

sources in #1 post
 
Last edited:
Upvote 0

pertov

Member
That's what I experienced:
JavaScript:
function nt(){
    BB.CallSub("lg",false,"before md5");
    s=BB.CallSub("md5z",false,s);
    mss.innerText =">> md5="+ s;
    BB.CallSub("lg",false,"after md5 =" + s);
    //alert("1="+s);
}
in debug mode=
1742215952121.png
>>return value =worked
 
Upvote 0

FrostCodes

Active Member
Licensed User
Longtime User
Maybe check my examples here:

 
Upvote 0

pertov

Member
thanks for Our answers, I'm resigned
1.WebViewExtras2.DefaultJavascriptInterface..CallSub(...) in debug mode - Does not return a value result
2.if sub no exists WebViewExtras2.DefaultJavascriptInterface..CallSub(...) = returns a string error message instead of Null or Error
 

Attachments

  • testcall_JS_J_JS.zip
    9.7 KB · Views: 46
Upvote 0
Top