1

Possible Duplicate:
Open PDF in Android

I would like to open a PDF file with Adobe Reader from my android application.

I've a PDF file in /mnt/sdcard called test.pdf, and I'm using the next code:

file = new File ("/mnt/sdcard/test.pdf");

if (file.exists())
{
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.fromFile(file));
    intent.setType("application/pdf");
    intent.setPackage("com.adobe.reader");          
    startActivity(intent);              
}

Adobe Reader is opened when this code is executed, but the file is not opened. The file is valid.

What is the problem?

Community
  • 1
  • 1
Eduardo
  • 1,169
  • 5
  • 21
  • 56

2 Answers2

6

try this.

Uri path = Uri.fromFile(file);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(path, "application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
Dipak Keshariya
  • 22,193
  • 18
  • 76
  • 128
Sahil Mahajan Mj
  • 11,033
  • 8
  • 53
  • 100
1

try this code

File file=new File("/mnt/sdcard/test.pdf");
if(file.exists())
{
    Uri path=Uri.fromFile(file);
    Intent intent=new Intent(Intent.ACTION_VIEW);
    intent.setDataAndType(path, "application/pdf");

    try
    {
        startActivity(intent);
    }
    catch(ActivityNotFoundException e)
    {
        Toast.makeText(TestActivity.this, "No software for PDF", Toast.LENGTH_SHORT).show();
    }
}
Dipak Keshariya
  • 22,193
  • 18
  • 76
  • 128
Naveen Kumar
  • 3,738
  • 4
  • 29
  • 50