Edu*_*rdo 1 pdf file-io android
可能重复:
在Android中打开PDF
我想从我的Android应用程序用Adobe Reader打开一个PDF文件.
我在/ mnt/sdcard中有一个名为test.pdf的PDF文件,我正在使用下一个代码:
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);
}
Run Code Online (Sandbox Code Playgroud)
执行此代码时会打开Adobe Reader,但不会打开该文件.该文件有效.
问题是什么?
试试这个.
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);
Run Code Online (Sandbox Code Playgroud)