Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
983 views
in Technique[技术] by (71.8m points)

android - Google docs PDF viewer

In accordance with advice of many I'm trying to use goolge docs to show a pdf in a WebView.

Here is my code:

@SuppressLint("SetJavaScriptEnabled")
public void setDocumentPath(final String path) {
    WebView webView = (WebView) findViewById(R.id.webview);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setPluginsEnabled(true);
    webView.loadUrl("https://docs.google.com/viewer?url=http://www.selab.isti.cnr.it/ws-mate/example.pdf");
}

The PDF is just some example I found online. It works in my browser, but on my android emulator and device it displays a "Webpage not available".

Both are running android 4.0.

Is there anything obvious I'm missing? Thank you.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

And in case someone is beating their head against the wall in a similar situation, it's a case of forgotten permissions.

<uses-permission android:name="android.permission.INTERNET" /> 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...