user1390225
user1390225

Reputation: 23

How to read a pdf file stored in sdcard using adobe reader installed in the android device?

i new to android application developemnt. I am trying to open the pdf file stored in sd card.I used this code snippet but this opens the viewer in the device but not the file given in the path. Any help appreciated.

    Intent intent = new  Intent(Intent.ACTION_VIEW,Uri.parse("Environment.getExternalStorageDirectory().getPath()+/sample.pdf"));
    intent.setType("application/pdf");
    intent.setPackage("com.adobe.reader"); selects the adobe reader directly 
    PackageManager pm = getPackageManager();
    List<ResolveInfo> activities = pm.queryIntentActivities(intent,0);
    if (activities.size() >= 0) 
            {
    startActivity(intent);


    } else {
    Toast.makeText(this, "No Application Available to View PDF",

        Toast.LENGTH_SHORT).show();
    }

Upvotes: 0

Views: 2728

Answers (2)

Ram kiran Pachigolla
Ram kiran Pachigolla

Reputation: 21191

you can read pdf file from sdcard by giving the path and try the following.

File pdfFile = new File(path); 
if(pdfFile.exists()) 
{

    Uri path = Uri.fromFile(pdfFile); 
    Intent pdfIntent = new Intent(Intent.ACTION_VIEW);
    pdfIntent.setDataAndType(path, "application/pdf");
    pdfIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    try
    {
        startActivity(pdfIntent);
    }
    catch(ActivityNotFoundException e)
    {
        Toast.makeText(uractivity.this, resource.getString(R.string.noapplicationpdf), Toast.LENGTH_LONG).show(); 
    }
}

Upvotes: 1

ρяσѕρєя K
ρяσѕρєя K

Reputation: 132982

You can try something like

Intent intent = new Intent(Intent.ACTION_VIEW);
File file = new File(filename);
intent.setDataAndType( Uri.fromFile( file ), "application/pdf" );
startActivity(intent);

or

Intent intent = new Intent();
intent.setPackage("com.adobe.reader");
intent.setDataAndType(Uri.fromFile(file), "application/pdf");
startActivity(intent);

Upvotes: 0

Related Questions