android WebView preview office document
Need to implement in the latest project: preview office documents in Android. Find the information on the Internet and see these three opening methods:
1. Convert the document into html format, and then use WebViewer to load and display the local html.
2. Invoke wps to open.
3. Use WebView + online preview to open the address of the office document.
My needs just need to preview the document, so I chose the third opening posture, no nonsense on the code.
WebView wv_office = (WebView) findViewById(R.id.wv_office);
wv_office.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// TODO Auto-generated method stub
view.loadUrl(url);
return true;
}
@Override
public void onPageFinished(WebView view, String url) {
// TODO Auto-generated method stub
super.onPageFinished(view, url);
}
});
// webview必须设置支持Javascript才可打开
wv_office.getSettings().setJavaScriptEnabled(true);
// 设置此属性,可任意比例缩放
wv_office.getSettings().setUseWideViewPort(true);
//通过在线预览office文档的地址加载
wv_office.loadUrl("https://view.officeapps.live.com/op/view.aspx?src="+文档url);
Don't forget network permissions!
<uses-permission android:name="android.permission.INTERNET" />