Understanding Android's webview addjavascriptinterface

后端 未结 3 1287
感动是毒
感动是毒 2020-12-08 15:38

I know that to interact from Javascript to Java you have to inject a Java object using the addjavascriptInterface method in webview.

Here is the problem I am facing.

3条回答
  •  有刺的猬
    2020-12-08 16:00

    (copied from my response on a similar question)

    I've taken Jason Shah's and Mr S's implementation as the building block for my fix and improved upon it greatly.

    There's just far too much code to put into this comment I'll just link to it.

    • Details: http://twigstechtips.blogspot.com/2013/09/android-webviewaddjavascriptinterface.html
    • Source: https://github.com/twig/twigstechtips-snippets/blob/master/GingerbreadJSFixExample.java

    Key points are:

    • Applies to all versions of Gingerbread (2.3.x)
    • Calls from JS to Android are now synchronous
    • No longer have to map out interface methods manually
    • Fixed possibility of string separators breaking code
    • Much easier to change JS signature and interface names

提交回复
热议问题