How to open doc file in android from url

左心房为你撑大大i 提交于 2019-12-10 22:34:15

问题


I want to read doc file from url in my android application, i am doing it with google docs like below but i am not getting result.

webView.loadUrl("http://docs.google.com/gview?embedded=true&url="+urlOfDocument);

is there any solution about that? how can i achieve it?

Thank You


回答1:


try this

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);

    }
}

EDIT: IF not work, check your URL in device browser to ensure it is working fine




回答2:


In my situation, there is result coming. But your WebView's size is 0 and 0.

So you need to reset the LayoutParam by implement the "onPageFinished."



来源:https://stackoverflow.com/questions/24772663/how-to-open-doc-file-in-android-from-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!