`
bolutes
  • 浏览: 868307 次
文章分类
社区版块
存档分类
最新评论

Android WebView学习

 
阅读更多

项目工程截图:


效果截图:


Code:

要想全面的了解这个还得要看一下这个网页的html代码,尤其是对javascript的处理的部分:

这是demo.html的代码:

从上面不难看出

这个的作用就是点击的时候,调用那个javascript函数wave。这个函数的注释部分:This is not called on the UI thread. Post a runnable to invokeloadUrl on the UI thread.

public voidaddJavascriptInterface(Objectobj,StringinterfaceName)

Since:API Level 1

Use this function to bind an object to JavaScript so that the methods can be accessed from JavaScript.

IMPORTANT:

  • Using addJavascriptInterface() allows JavaScript to control your application. This can be a very useful feature or a dangerous security issue. When the HTML in the WebView is untrustworthy (for example, part or all of the HTML is provided by some person or process), then an attacker could inject HTML that will execute your code and possibly any code of the attacker's choosing.
    Do not use addJavascriptInterface() unless all of the HTML in this WebView was written by you.
  • The Java object that is bound runs in another thread and not in the thread that it was constructed in.

Parameters
obj interfaceName
The class instance to bind to JavaScript, null instances are ignored.
The name to used to expose the instance in JavaScript.
boolean android.os.Handler.post(Runnable r)

Causes the Runnable r to be added to the message queue. The runnable will be run on the thread to which this handler is attached.(在这个程序里面也就是说会在主线程)

Parameters:
r The Runnable that will be executed.
Returns:
Returns true if the Runnable was successfully placed in to the message queue. Returns false on failure, usually because the looper processing the message queue is exiting.

public voidsetWebChromeClient(WebChromeClientclient)

Since:API Level 1

Set the chrome handler. This is an implementation of WebChromeClient for use in handling JavaScript dialogs, favicons, titles, and the progress. This will replace the current handler.

Parameters
client
An implementation of WebChromeClient.
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics