Android WebView common problems and Solutions

At present, HTML5 is developing very rapidly. Many native apps will be embedded in web pages to meet the changing market demand. However, the default function supported by Android WebView is very weak, and many places need to be customized to achieve the desired effect. And WebView will have different degrees of bugs in different versions. The following editor will sort out the common problems in WebView as follows:

1. Customize the error display interface for WebView:

2. WebView cookie cleaning:

3. Clean up cache and History:

5. URL interception: Android WebView cannot intercept the fragment jump in the page. However, if the URL jumps, the page will be refreshed and the experience of H5 page will decline. Only JS methods can be injected into WebView. 6. Processing non hyperlink requests (such as Ajax requests) in WebView: sometimes it is necessary to add a request header, but for non hyperlink requests, there is no way to intercept and add a request header with webview.loadurl (string URL, HashMap headers) method. At present, a temporary solution is used: first, it is necessary to add a special tag / protocol in the URL, For example, intercept the corresponding request in the onwebviewresource method, and then splice the request header to be added to the end of the URL in the form of get. In the shouldinterceptrequest () method, you can intercept all resource requests in the web page, such as loading JS, pictures and Ajax requests

7. Display the picture on the page first:

8. Screen out the long press event, because the WebView will call the copy control of the system on time:

9. Add flash support to WebView:

The above content is the full description of common problems and solutions for Android WebView in this paper. I hope you like it.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>