【发布时间】:2015-02-02 23:13:12
【问题描述】:
我在这里想要做的是。我在我的 SD 卡中找到 Pdf 文件夹并单击该文件,然后使用 Adobe Reader 完成操作。我成功地完成了读取 SD 卡选项,它将布局中的所有 pdf 文件显示为网格视图。但是当我单击 pdf 文件时,它会打开 Adobe reader 但无法打开文件。它说“无法打开该文档,因为它不是有效的 pdf 文档”。这是我的代码-
这是在 SD 卡中查找文件和文件夹的代码
public View onCreateView(LayoutInflater inflater,ViewGroup container, Bundle savedInstanceState)
{
View view =inflater.inflate(R.layout.magica_pdf_layout, container, false);
// Check for SD Card
if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))
{
Toast.makeText(PdfFragment.this.getActivity(), "Error! No SDCARD Found!", Toast.LENGTH_LONG).show();
}
else
{
// Locate folder in your SD Card
file = new File(Environment.getExternalStorageDirectory()+ File.separator + "Book");
// Create a new folder if no folder named exist
file.mkdirs();
}
这里是onclick方法的部分
// Capture gridview item click
grid.setOnItemClickListener(new OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> parent, View view,int position, long id)
{
// get clicked file name from gridview
String pdfname=(String)parent.getItemAtPosition(position);
//prepare pdf file url
selectedFile = new File(file.getAbsolutePath()+File.separator +pdfname+".pdf");
Intent pdfIntent = new Intent();
pdfIntent.setAction(android.content.Intent.ACTION_VIEW);
pdfIntent.setDataAndType(Uri.fromFile(selectedFile), "application/pdf");
startActivity(pdfIntent);
}
});
【问题讨论】:
-
显示如何准备
file路径? -
file = new File(Environment.getExternalStorageDirectory()+ File.separator + "Book");文件.mkdirs();
-
请在帖子中编辑更多代码以了解问题
-
Book 是 SD 卡中的一个文件夹,将所有 pdf 文件读入该文件夹。它读取所有 pdf 文件并在活动中显示为网格视图。当我单击 pdf 文件 adobe reader 启动但显示 pdf 文件无效的消息。
-
看我的回答可能有帮助
标签: android pdf android-intent