Rajesh Panchal
Rajesh Panchal

Reputation: 1170

How to open doc file in android from url

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

Upvotes: 3

Views: 3562

Answers (2)

hsu.tw
hsu.tw

Reputation: 148

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."

Upvotes: 0

Sree
Sree

Reputation: 3194

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

Upvotes: 4

Related Questions