android - how to open pdf in webview without gdoc from Url -
i try open pdf url in webview below code , found solutions gdoc not useful me because want show pdf in view mode , user should not download , need clear cache after press
code :
mwebview.setwebchromeclient(new webchromeclient()); websettings settings = mwebview.getsettings(); settings.setpluginstate(websettings.pluginstate.on); mwebview.setwebviewclient(new mybrowser()); mwebview.setbackgroundcolor(0x00000000); settings.setallowfileaccess(false); settings.setbuiltinzoomcontrols(true); settings.setsupportzoom(true); settings.setusewideviewport(true); settings.setloadwithoverviewmode(false); settings.setsaveformdata(false); settings.setjavascriptenabled(true);
use code:
webview webview = (webview) findviewbyid(r.id.my_webview); webview.setwebviewclient(new mywebviewclient()); webview.addview(webview.getzoomcontrols()); webview.getsettings().setjavascriptenabled(true); webview.loadurl("http://docs.google.com/gview?embedded=true&url=**pdfurl**");
also, add permission in manifest needs internet connectivity (must required)
<uses-permission android:name="android.permission.internet"/>
this work!
if direct url not work lode this
webview.getsettings().setpluginsenabled(true); webview.getsettings().setallowfileaccess(true); webview.loadurl(pdf);
also,
string pdf="<iframe src='http://docs.google.com/viewer?url=+location pdf file+' width='100%' height='100%' style='border: none;'></iframe>";