Android - How I can call javascript function and getting the retur value from javascript function -


I think many questions have been asked earlier about this addiction, but I have one of them for me

I want to get value from JS function on my Java Android

sample,

  function GetStringToMyAndroid (stringFromAndroid) {var myJsString = "Hello World" +; Return myJsString; }  

Now I want to call getStringToMyAndroid ("This string from Android") and get myJsString return to your Android

  WebView.loadUrl ("Javascript: GetStringToMyAndroid ('This string is called Android')") but   

I want to get value from string or JS function

very much appreciate if I can have a detailed procedure Thanks.

Note: My Android is running minimal SDK Android 3.0 Honeycomb

API level For & lt; 19 Whether the use of the JavaScript interface (my preferred method below) or the abduction of the Onge Alert method and instead of using the alert () dialogue, it means that you You can not use the alert () function for the desired purpose.

See:

  Webview JavaScript Interface (new JS interface (), "Android app"); WebView.loadUrl ("javascript: doStringToMyAndroid ('this string from Android')")  

JS interface:

  public class JsInterface () {@JavascriptInterface zero attribute string (string value) {// string to webview log. Received from ("MyApp", value); }}  

Javascript:

  function doStringToMyAndroid (stringFromAndroid) {var myJsString = "Hello World"; // Call JavascriptInterface instead of returning the price window. AndroidApp.receiveString (myJsString); }  

But at API level 19+, we now evaluate the JavaScript method:

  WebView.evaluateJavascript ("(function () {getStringToMyAndroid ( "" MyJsString + "');});" New Value Callback "; String & gt; () {@ Override Public Vide On Receive Well (String S) {Log D. (" Login ", S ); // program     } });  

Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -