1

I have a webview in my app and I got it working like this

webview = (WebView) findViewById(R.id.mainWebView); webview.loadUrl("https://www.google.com"); 

But if I try to load the non mobile version of the https://uniondining.sodexomyway.com/Images/MAR2015dutchCalendar_000_tcm1792-59025.pdf it exits out of the app.

How can I load the mobile version of site in my app?

Thanks

3 Answers 3

2

Unfortunately, Android does not support viewing PDFs out of the box in a WebView. Luckily, Google has a nifty little tool that allows you to perform this very task quite easily using Google Docs. Basically we will embed our PDF in a Google Doc page on-the-fly and load that.

You can use Google Docs Viewer to read your pdf online: Here's the code:

WebView webview = (WebView) findViewById(R.id.webview); webview.getSettings().setJavaScriptEnabled(true); String pdf = "http://www.adobe.com/devnet/acrobat/pdfs/pdf_open_parameters.pdf"; webview.loadUrl("http://docs.google.com/gview?embedded=true&url=" + pdf); 

If you use the view only url the user is not propted to login to there google account.

Sign up to request clarification or add additional context in comments.

Comments

0

You're trying to open a link to PDF file. While desktop browsers like Chrome can open it, Android WebView has no builtin PDF reading possibility, so you can't show this inside the WebView. Instead, you can try to download the file and open it with some PDF library like MuPDF.

Also, you need to check if you have permission android.permission.INTERNET set up in your AndroidManifest.xml

Comments

0

Check your URL again. You are trying to loead a pdf which webView can't load but desktop browsers like IE and chrome. But in case of android WebView cant load PDF files.

You can use android pdf library also to create your pdf viewer otherwise you can display it using any pdf viewer installed on your mobile.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.