我必须将 pdf 文件与我的应用程序一起发送,并将它们显示为列表,单击时每个文件都应在 Adobe 阅读器中打开。我尝试将 pdf 文件放在 /assets 文件夹中,也放在 /res/raw 文件夹中。但无论哪种情况,我都会遇到 ActivityNotFound 异常。代码和异常消息如下。
将文件放在 /assets/pdf 文件夹中
try {
files = amanager.list("pdf");
//AssetFileDescriptor fd = amanager.openFd(files[0]);
Uri path = Uri.parse("android.resource://com.csg.android.myproject/assets/pdf/csgsample") ;
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setPackage("com.adobe.reader");
intent.setDataAndType(path, "application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
try {
startActivity(intent);
}
catch (ActivityNotFoundException e){
Toast.makeText(FirstTab.this, "NO Viewer", Toast.LENGTH_SHORT).show();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
将文件放在 /res/raw 文件夹中
Uri.parse("android.resource://com.csg.android.myproject/raw/csgsample") ;
例外:
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=android.resource://com.csg.android.myproject/assets/pdf/csgsample typ=application/pdf flg=0x4000000 pkg=com.adobe.reader }
任何帮助将不胜感激。
提前致谢, 纳文