如何读取存储在使用安装在Android设备的Adobe Reader SD卡的PDF文件? [英] How to read a pdf file stored in sdcard using adobe reader installed in the android device?

查看:461
本文介绍了如何读取存储在使用安装在Android设备的Adobe Reader SD卡的PDF文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚接触android应用更新发育。我试图打开存储在SD PDF文件card.I用这个code片段,但这将在设备中的浏览器,但没有在路径指定的文件。任何帮助AP preciated。

 意向意图=新Intent(Intent.ACTION_VIEW,Uri.parse(\"Environment.getExternalStorageDirectory().getPath()+/sample.pdf\"));
    intent.setType(应用程序/ PDF格式);
    intent.setPackage(com.adobe.reader);直接选择的Adobe Reader
    软件包管理系统下午= getPackageManager();
    清单< ResolveInfo>活动= pm.queryIntentActivities(意向,0);
    如果(activities.size()> = 0)
            {
    startActivity(意向);
    }其他{
    Toast.makeText(这一点,没有应用程序可用来查看PDF        Toast.LENGTH_SHORT).show();
    }


解决方案

您可以通过给路径读取SD卡的PDF文件,并​​尝试以下操作。

 文件pdfFile =新的文件(路径);
如果(pdfFile.exists())
{    URI路径= Uri.fromFile(pdfFile);
    意图pdfIntent =新意图(Intent.ACTION_VIEW);
    pdfIntent.setDataAndType(路径,应用程序/ PDF格式);
    pdfIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    尝试
    {
        startActivity(pdfIntent);
    }
    赶上(ActivityNotFoundException E)
    {
        Toast.makeText(uractivity.this,resource.getString(R.string.noapplicationpdf),Toast.LENGTH_LONG).show();
    }
}

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();
    }

解决方案

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(); 
    }
}

这篇关于如何读取存储在使用安装在Android设备的Adobe Reader SD卡的PDF文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆