Passing a Javascript Variable to Android Activity?

前端 未结 3 1795
情歌与酒
情歌与酒 2020-12-21 19:00

Basically I want get data I already have accessed from javascript and passing it to Java/Android so that I can work with it there.

     /* An instance of thi         


        
3条回答
  •  半阙折子戏
    2020-12-21 19:12

    You can not access stored javascript variables, you must do it through a function call. You have to call it from javascript in your html page, for example:

    TheNameOfYourInterface.setX('value');
    

    TheNameOfYourInterface will be a javascript object when you add the interface to the webview via

    YourWebView.addJavascriptInterface(new MyJavaScriptInterface(),"TheNameOfYourInterface");
    

    so you can do the logic on your webview and call the interface when you set the data so the method in the Java side will be called.

提交回复
热议问题