Rectangle 27 5

the above IP is public

No, it is not. IPs in the range you've provided are internal IP addresses used within a LAN network. Your public IP is something different, and you will have to find that out and use it to serve up your file using Google Docs.

You can get your public IP by simply typing my public ip into Google.

Additionally, public IPs change quite frequently (unless you're paying extra for a static IP to your ISP), so you would be better of hiring a server, or keeping your file in public domain somewhere to allow unbroken access to it.

Open pdf in webview of android - Stack Overflow

android android-webview
Rectangle 27 2

Here load with progressDialog. Need to give WebClient otherwise it force to open in browser:

final ProgressDialog pDialog = new ProgressDialog(context);
    pDialog.setTitle(context.getString(R.string.app_name));
    pDialog.setMessage("Loading...");
    pDialog.setIndeterminate(false);
    pDialog.setCancelable(false);
    WebView webView = (WebView) rootView.findViewById(R.id.web_view);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);
            pDialog.show();
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            pDialog.dismiss();
        }
    });
    String pdf = "http://www.adobe.com/devnet/acrobat/pdfs/pdf_open_parameters.pdf";
    webView.loadUrl("http://drive.google.com/viewerng/viewer?embedded=true&url=" + pdf);

android - How can I display a pdf document into a Webview? - Stack Ove...

android pdf webview
Rectangle 27 2

WebView

The URL you posted on your comments it displayed pdf file in native web browser because of it uses Google Docs.

If you want to display pdf file in your webview then using Google Docs pass url of your pdf file which located on server not in your local.

Update: Code for display pdf file located on net in webview.

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

But the question was for how to do this for a local PDF file, does this solution work in that case too?

android load local(in Asset/Res/External Storage) pdf file in webview ...

android android-webview
Rectangle 27 3

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    WebView webView=new WebView(MainActivity.this);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setPluginState(PluginState.ON);

    webView.setWebViewClient(new Callback());

    String pdfURL = "http://dl.dropboxusercontent.com/u/37098169/Course%20Brochures/AND101.pdf";
    webView.loadUrl("http://docs.google.com/gview?embedded=true&url=" + pdfURL);

    setContentView(webView);
}

private class Callback extends WebViewClient {
    @Override
    public boolean shouldOverrideUrlLoading(
            WebView view, String url) {
        return(false);
    }
}

android - Display pdf on WebView - Stack Overflow

android pdf webview
Rectangle 27 3

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    WebView webView=new WebView(MainActivity.this);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setPluginState(PluginState.ON);

    webView.setWebViewClient(new Callback());

    String pdfURL = "http://dl.dropboxusercontent.com/u/37098169/Course%20Brochures/AND101.pdf";
    webView.loadUrl("http://docs.google.com/gview?embedded=true&url=" + pdfURL);

    setContentView(webView);
}

private class Callback extends WebViewClient {
    @Override
    public boolean shouldOverrideUrlLoading(
            WebView view, String url) {
        return(false);
    }
}

android - Display pdf on WebView - Stack Overflow

android pdf webview
Rectangle 27 2

to sum it up : Usage of file:/// before your actual path should solve your problem for everything except .pdf files

Webview does not support PDF in android :(. You need to use google doc according to different sources.

file:/// works with test.html but without /mnt file:///data/data/com.example.android/files/Docs/test.html"); Still blank for pdf...

i added eclipse logs on top when i am trying to open a pdf file

unfortunatly, Webview does not support PDF in android. You will need to use google doc.

android - Can't open a local PDF in webview using file:// - Stack Over...

android android-webview
Rectangle 27 2

to sum it up : Usage of file:/// before your actual path should solve your problem for everything except .pdf files

Webview does not support PDF in android :(. You need to use google doc according to different sources.

file:/// works with test.html but without /mnt file:///data/data/com.example.android/files/Docs/test.html"); Still blank for pdf...

i added eclipse logs on top when i am trying to open a pdf file

unfortunatly, Webview does not support PDF in android. You will need to use google doc.

android - Can't open a local PDF in webview using file:// - Stack Over...

android android-webview
Rectangle 27 125

You can use Google Docs Viewer to read your pdf online:

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://drive.google.com/viewerng/viewer?embedded=true&url=" + pdf);

google reader is reliable? If the google changes the URL?

You've reached the bandwidth limit for viewing or downloading files that aren't in Google Docs format....

This solution is absolutely terrible. The fact that so many of you consider putting something this ugly in your app worries me. This page is designed for desktop. This site is clearly optimized for desktop. Using this on mobile is not a good mobile experience.

android - How can I display a pdf document into a Webview? - Stack Ove...

android pdf webview
Rectangle 27 27

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

https://docs.google.com/viewer?url=http://my.domain.com/yourPdfUrlHere.pdf

android - How can I display a pdf document into a Webview? - Stack Ove...

android pdf webview
Rectangle 27 15

Implement a download listener to handle any kind of download:

webView.loadUrl(uriPath);

webView.setDownloadListener(new DownloadListener() {
    @Override
    public void onDownloadStart(String url, String userAgent,
            String contentDisposition, String mimetype,
            long contentLength) {

        startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
    }
});

when do this setDownloadListener will be called @Mobistry Is there any other way to download the pdf file, Question

This code is downloading the file but it is opening the web browser and coming back to the app,How to stop this behaviour.what to do if I don't want to get that browser pop-up

This is the a great answer. It's simple - this way you can let browser handle the downloading. But if you want to do it inside webview, you can also - you have the URL passed.

android - Downloading pdf through web browser and webview - Stack Over...

android pdf android-webview
Rectangle 27 13

You should create WebViewClient and set it to your webview. Every time you click a link WebViewClient's shouldOverrideUrlLoading method will be called. Check that url points to pdf file and do what you want. For example, you can view pdf.

webView.setWebViewClient(new WebViewClient() {
    public boolean shouldOverrideUrlLoading (WebView view, String url) {
        if (url.endsWith(".pdf")) {
            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
            // if want to download pdf manually create AsyncTask here
            // and download file
            return true;
        }
        return false;
    }
});

can you help me i had open many html5 pages in webview in between one page downlod pdf file. i had used this code for it but it will not download pdf file

android - Downloading pdf through web browser and webview - Stack Over...

android pdf android-webview
Rectangle 27 1

here is a SO post for Opening a link in safari,

Hi, I already have my PDF displayed. That PDF has text and a link to another website. When I click on that link I want to open that website, not any pdf. I know how to open PDF I want to know how to get link from PDF page and open it.

@Jaliya Thanks but this is not what I am looking for. My I am unable to detect my link in iphone. How can I detect the link and make request.

Open link in webView or safari from PDF page in iphone SDK? - Stack Ov...

iphone pdf quartz-2d
Rectangle 27 2

hi @paulo can you please provide me with example about how to use this with the android?

android - How can I display a pdf document into a Webview? - Stack Ove...

android pdf webview
Rectangle 27 1

Opening a pdf using google docs is a bad idea in terms of user experience. It is really slow and unresponsive.

Solution after API 21 Since api 21, we have PdfRenderer which helps converting a pdf to Bitmap.

I've never used it but is seems easy enough.

Solution for any api level Other solution is to download the PDF and pass it via Intent to a dedicated PDF app which will do a banger job displaying it. Fast and nice user experience, especially if this feature is not central in your app.

Use this code to download and open the PDF

public class PdfOpenHelper {

public static void openPdfFromUrl(final String pdfUrl, final Activity activity){
    Observable.fromCallable(new Callable<File>() {
        @Override
        public File call() throws Exception {
            try{
                URL url = new URL(pdfUrl);
                URLConnection connection = url.openConnection();
                connection.connect();

                // download the file
                InputStream input = new BufferedInputStream(connection.getInputStream());
                File dir = new File(activity.getFilesDir(), "/shared_pdf");
                dir.mkdir();
                File file = new File(dir, "temp.pdf");
                OutputStream output = new FileOutputStream(file);

                byte data[] = new byte[1024];
                long total = 0;
                int count;
                while ((count = input.read(data)) != -1) {
                    total += count;
                    output.write(data, 0, count);
                }

                output.flush();
                output.close();
                input.close();
                return file;
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }
    })
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(new Subscriber<File>() {
                @Override
                public void onCompleted() {

                }

                @Override
                public void onError(Throwable e) {

                }

                @Override
                public void onNext(File file) {
                    String authority = activity.getApplicationContext().getPackageName() + ".fileprovider";
                    Uri uriToFile = FileProvider.getUriForFile(activity, authority, file);

                    Intent shareIntent = new Intent(Intent.ACTION_VIEW);
                    shareIntent.setDataAndType(uriToFile, "application/pdf");
                    shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                    if (shareIntent.resolveActivity(activity.getPackageManager()) != null) {
                        activity.startActivity(shareIntent);
                    }
                }
            });
}
<provider
        android:name="android.support.v4.content.FileProvider"
        android:authorities="${applicationId}.fileprovider"
        android:exported="false"
        android:grantUriPermissions="true">

        <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/file_paths" />

    </provider>

Finally create a file_paths.xml file in the resources foler

<?xml version="1.0" encoding="utf-8"?>
<paths>
    <files-path name="shared_pdf" path="shared_pdf"/>
</paths>

android - How can I display a pdf document into a Webview? - Stack Ove...

android pdf webview
Rectangle 27 5

Access the preferences property of the WebView, and disable plugins.

[webView.preferences setPlugInsEnabled:NO];

objective c - Adobe Acrobat is interfering with PDF files shown with W...

objective-c osx cocoa webkit acrobat
Rectangle 27 2

The best way, if it works, would be to use a filesystem URL. To get this use FileEntry.toURL

These don't work on external files (i.e. files that come from chrome.fileSystem.chooseEntry and are outside the app's sandbox) but should work for files in the app's sandbox.

Note, I am referring to filesystem:// urls not file://urls, which won't work as Marc Rochkind has pointed out in his answer.

Disclaimer: I haven't tested this, but I believe it should work.

@Marc I was referring to filesystem:// urls, not file:// urls. These are URLs which refer directly to items in sandboxed file systems. Read the link to FileEntry.toURL provided for more information. Because these are sandboxed and only accessible by the origin that created them, they don't have the same restrictions as file:// URLs.

System won't let me unless the answer is edited. Edit it and I'll add the 1 back.

google chrome app - Access downloaded pdf file path in HTML5 file syst...

google-chrome-app html5-filesystem
Rectangle 27 0

for the actual download logic check onDownloadStartNoStream in the below link

sure i will give it a try.If anyone here can fix my above code to my requirement it will be a great help..i have being working on this for a weeks time trying to figure out proper solution

android - How to use a download Manager in a webview to download pdf/p...

android webview
Rectangle 27 0

I think you should use custom library for getting that done .See this and this

But there is a way for displaying PDF with out calling another application

This is a way for showing PDF in android app that is embedding the PDF document to android webview using support from http://docs.google.com/viewer

and in manifest provide

Caution : I am not aware of compatibility issues with various android versions

In this approach the drawback is you need internet connectivity . But i think it satisfy your need

There is also an HTML5 container enhancement <iframe> to provide more control over pdf which you can use along with this See this

Good library to view pdf in webview in android - Stack Overflow

android pdf webview 3rd-party-library
Rectangle 27 0

You'll have to download the files first, so Android can find an appropriate application to open them with, since Uri.parse(url) will give you a website address, which is normally assigned to the browser (and will therefore open in it).

To download the files, you can use the DownloadManager-service or write your own code to do so. Once you have the file in a temporary location, you can open it by using your above method.

If you want to delete the file after the user viewed it, one idea would be to do it in your activities onResume()-method, which will be called when the user navigates back from viewing the file (using the back-button).

Although, I would rather put the files in the internal cache and wipe it every now and then. Android will do a little house-keeping itself, too:

When the device is low on internal storage space, Android may delete these cache files to recover space.

you should not rely on the system to clean up

Android webview download and view pdf, xls or doc files - Stack Overfl...

android pdf android-webview