android - Can't load images and videos inside Webview with JavaScript enabled -
i'm loading data website webview in application.and need make video plays inside webview.my problem when don't use setjavascriptasenable images , video loads fine can't play video inside webview gives me following error
an error occurred. try watching video on youtube or enabe javascript.
however when use setjavascriptasenable(true)
images , videos inside webview
disappears following image.
here's code webview
void setupwebview(final webview webview) { if (build.version.sdk_int >= build.version_codes.kitkat) { webview.getsettings().setlayoutalgorithm(websettings.layoutalgorithm.text_autosizing); } else { webview.getsettings().setlayoutalgorithm(websettings.layoutalgorithm.normal); } webview.setwebviewclient(new webviewclient() { @override public void onpagefinished(webview view, string url) { // add padding html page webview.loadurl("javascript:(function(){ document.body.style.paddingbottom = '30px'})();"); } @override public boolean shouldoverrideurlloading(webview view, string request) { if (request.contains("http")) {// todo: 14/08/2017 use regs log.d("url", request); new checkifimageasynctask().execute(request); return true; } return false; } @requiresapi(api = build.version_codes.lollipop) @override public boolean shouldoverrideurlloading(webview view, webresourcerequest request) { string url = request.geturl().tostring(); if (url.contains("http")) { new checkifimageasynctask().execute(url); return true; } return false; } }); // settings webview.setwebchromeclient(new webchromeclient()); webview.getsettings().setpluginstate(websettings.pluginstate.on); webview.getsettings().setpluginstate(websettings.pluginstate.on_demand); webview.getsettings().setallowfileaccess(true); webview.getsettings().setjavascriptenabled(true); webview.getsettings().setdomstorageenabled(true); string data = "<div>" + post.getcontent() + " </div>"; webview.loaddatawithbaseurl("file:///android_asset/", gethtmldata(data), "text/html", "utf-8", null); } private class checkifimageasynctask extends asynctask<string, void, boolean> { private string url; @override protected boolean doinbackground(string... strings) { url = strings[0]; urlconnection connection = null; boolean isimage = false; try { connection = new url(url).openconnection(); string contenttype = connection.getheaderfield("content-type"); isimage = contenttype.startswith("image/"); } catch (ioexception e) { e.printstacktrace(); } return isimage; } @override protected void onpostexecute(boolean isimage) { try { if (isimage) { intent intent = new intent(postdetailsactivity.this, fullscreenimageactivity.class); intent.putextra("coverimage", url); startactivity(intent); } else { intent intent = new intent(intent.action_view, uri.parse(url)); startactivity(intent); } } catch (exception e) { log.e("error", e.getmessage()); firebasecrash.report(new exception(e.getmessage())); } } }
i searched lot , can't figure out. appreciated. in advance.
Comments
Post a Comment