How to open Excel, .doc files in Webview in Android?

后端 未结 2 929
鱼传尺愫
鱼传尺愫 2021-02-14 20:23

How can I open Excel and .doc file in Android webview. Can google doc support it?

2条回答
  •  深忆病人
    2021-02-14 20:36

    Yes Google doc support you to show doc or excel , pdf, txt or other formate.

    WebView urlWebView = (WebView)findViewById(R.id.containWebView);
    urlWebView.setWebViewClient(new AppWebViewClients());
    urlWebView.getSettings().setJavaScriptEnabled(true);
    urlWebView.getSettings().setUseWideViewPort(true);
    urlWebView.loadUrl("http://docs.google.com/gview?embedded=true&url="
                    + "YOUR_DOC_URL_HERE"); 
    
    public class AppWebViewClients extends 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);
    
        }
    }
    

提交回复
热议问题