1
public class OpenPdf extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Button button = (Button) findViewById(R.id.OpenPdfButton);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                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();
                    }
                }
            }
        });
    }
}

I have tried this above code but no output can been seen on emulator.Please help me to solve my problem of reading a PDF on emulator

tpow
  • 7,600
  • 11
  • 59
  • 84
Aditi
  • 11
  • 1
  • 3
  • Hello Aditi, Welcome to Stackoverflow. Is your code running StartActivity without exceptions? If so, you may want to post the Activity of the PDF. I don't see where you are rendering the view of the document to your layout. – tpow Mar 05 '11 at 13:33
  • 1
    Probably your emulater don't have any `PDF Viewer` application installed. – Vikas Patidar Mar 05 '11 at 13:40

1 Answers1

2

I think the issue is in the Activity where you're trying to show the .pdf.

I haven't tried opening any .pdf files in any of my apps, but a cursory search says there is no native, easy way to do it. In other words, there is no Android class that makes it a snap to show your .pdf files - so you'll have to use a third party library, or roll your own.

See Render a PDF file using Java on Android

Community
  • 1
  • 1
tpow
  • 7,600
  • 11
  • 59
  • 84