html__ garbled problem of Android WebView loading iframe tag

Source: Internet
Author: User
Tags document cloud

My recent project needs to join the document Cloud returned directly to the IFRAME tag based on the data back in the background, but Android wanted to load it with WebView, and there were all sorts of problems in the middle. So just sort out the code and make a note for yourself and hope it will help you.

Directly on key code:

This is the interface returned by the IFRAME tag (this is a dynamic PPT text, the background can simply set the style) <iframe src= ' http://s2.sgld.org/op/embed.aspx?src=http:// S1.sgld.org:9191/d6ada647-9ed4-4b5b-b632-e94aa03f5694.pptx ' frameborder= ' 0 ' width= ' 100%px ' height= ' 100%px ' > </iframe>

public static WebView Pptweb (context Context,webview webview,string iframe,final ProgressBar pb) {
WebSettings websettings = Webview.getsettings ();
Set the WebView property to execute JavaScript script
Websettings.setjavascriptenabled (TRUE);
Websettings.setpluginstate (Pluginstate.on);/You can use Plug-ins
Set up a user agent (request header) to make the web side correctly judged
Webview.getsettings (). Setuseragentstring (
"Mozilla/5.0 (Windows NT 10.0; WOW64) applewebkit/537.36 (khtml, like Gecko) chrome/58.0.3029.110 safari/537.36 "
+ "; dccplan/1.5.8.30 ");
"Mozilla/5.0 (Windows NT 10.0; WOW64) applewebkit/537.36 (khtml, like Gecko) chrome/58.0.3029.110 safari/537.36 "
+ "; dccplan/1.5.8.30 "

1.5.8.30 change to the version number of your own project
Webview.setbackgroundcolor (0);//This will prevent white edges.
Setting Access to Files
Websettings.setallowfileaccess (TRUE);
Setting support Scaling
Websettings.setbuiltinzoomcontrols (TRUE);
Websettings.setusewideviewport (TRUE);//Set this property to scale at any scale
Websettings.setjavascriptcanopenwindowsautomatically (TRUE);
Websettings.setusewideviewport (TRUE);
Websettings.setdefaulttextencodingname ("Utf-8");
Websettings.setloadwithoverviewmode (TRUE);
Websettings.setsupportzoom (TRUE);
Websettings.setjavascriptcanopenwindowsautomatically (TRUE);
Websettings.setallowfileaccess (TRUE);
Websettings.setlayoutalgorithm (Layoutalgorithm.narrow_columns);
Websettings.setblocknetworkimage (TRUE);
Websettings.setsupportmultiplewindows (TRUE);
Websettings.setdisplayzoomcontrols (FALSE);
Webview.setscrollbarstyle (View.scrollbars_inside_overlay), if not plus, will show white edge
Webview.setverticalscrollbarenabled (FALSE);
Webview.sethorizontalscrollbarenabled (FALSE);
Set caching mode
Websettings.setcachemode (Websettings.load_no_cache);
Turn on DOM storage API functionality
Websettings.setdomstorageenabled (TRUE);

Webview.setwebchromeclient (New Webchromeclient ());
Android 5.0 WebView using WEBRTC, calling the camera with the microphone when the license
Webview.setwebchromeclient (New Webchromeclient () {
---WEBRTC:
@Override
public void Onpermissionrequest (Permissionrequest request) {
Request.grant (Request.getresources ());
}

@Override
public void onprogresschanged (webview view, int newprogress) {
TODO auto-generated method stubs
Pb.setprogress (newprogress)//Set Progress value

}
});
Websettings.getuseragentstring ();
Set Web View
Webview.setwebviewclient (New Webviewclient ());
Websettings.setappcacheenabled (TRUE);
Considering the loading speed of the Web page, we can call the Setwebchromeclient () method
Scroll bar in the entire page
Webview.setscrollbarstyle (View.scrollbars_inside_overlay);
if (! Textutils.isempty (iframe)) {
String url = "Webview.loaddata (URL, "text/html", "utf-8");
}
return webview;
}
public static class Webviewclient extends Webviewclient {
public boolean shouldoverrideurlloading (webview view, String URL) {
Return false;//returns False
}
@Override
public void onpagefinished (webview view, String URL) {
View.getsettings (). Setblocknetworkimage (false);
super.onpagefinished (view, URL);
}
public void onpagestarted (webview view, String URL) {
super.onpagestarted (view, URL, null);
}
@Override
public void Onreceivedsslerror (WebView view, Sslerrorhandler handler, sslerror error) {
Do not use super, otherwise some mobile phone can not access, because contains a handler.cancel ()
Super.onreceivedsslerror (view, handler, error);
Accept certificates for all Web sites, ignore SSL errors, and perform access to Web pages
Handler.proceed ();
}
}


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.