2

I'm new to android programming and I'm developing an application in android to open a PDF file from a server in my app. I've no idea about that. So please help me. How i can do this?

Thanks in advance.

2
  • 1
    It means you are having URL of your PDF?? Commented Jul 30, 2012 at 9:26
  • possible duplicate of Open PDF in a WebView Commented Feb 5, 2013 at 5:24

3 Answers 3

7

you have to try this code for open a pdf file in your application..

WebView webView = (WebView) findViewById(R.id.my_webview);
webView.setWebViewClient(new MyWebViewClient());
webView.addView(webView.getZoomControls());
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("http://docs.google.com/gview?embedded=true&url=http://myurl.com/demo.pdf");
Sign up to request clarification or add additional context in comments.

Comments

3
   String pdf = "http://www.xyzwebsite.com/yourfile.pdf"; //YOUR URL TO PDF
   String googleDocsUrl = "http://docs.google.com/viewer?url="+ pdfurl;
   Intent intent = new Intent(Intent.ACTION_VIEW);
   intent.setDataAndType(Uri.parse(googleDocsUrl ), "text/html");
   startActivity(intent);

Add this permission to manifest file

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

Comments

0
File file = new File("/sdcard/example.pdf");

                if (file.exists()) {
                    Uri path = Uri.fromFile(file);
                    Intent intent = new Intent(Intent.ACTION_VIEW);
                    intent.setDataAndType(path, "application/pdf");
                    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

                    try {
                        startActivity(intent);
                    } 
                    catch (ActivityNotFoundException e) {
                        Toast.makeText(OpenPdf.this, 
                            "No Application Available to View PDF", 
                            Toast.LENGTH_SHORT).show();
                          String pdf = "http://www.xyzwebsite.com/yourfile.pdf"; //YOUR URL TO PDF
                          String googleDocsUrl = "http://docs.google.com/viewer?url="+ pdfurl;
                          Intent intent = new Intent(Intent.ACTION_VIEW);
                          intent.setDataAndType(Uri.parse(googleDocsUrl ), "text/html");
                          startActivity(intent);


                    }
                }
            }

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.