经过几次问答后,我仍然找不到适合我当前问题的答案。
我有一个pdf文件(编译时就知道),它存储在我/res/raw文件夹中。
我尝试使用以下方法加载该文件:
InputStream is = getResources().openRawResource(R.raw.mypdf);然后,我想在设备上使用首选的pdf阅读器显示pdf(在意图中):
Intent i;
i = new Intent(Intent.ACTION_VIEW);
i.setDataAndType(file,"application/pdf");
startActivity(i);问题是,意图接受类型'File',而我的pdf被解读为'InputStream‘。
问题是:我如何显示pdf文件?例如,如何显示InputStream?或者如何存储pdf文件以允许用新File()打开?
发布于 2012-04-12 12:17:46
试试这个..。
//place pdf in asset folder just to tryUri file= Uri.parse("file:///android_asset/mypdf.pdf");
String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(MimeTypeMap.getFileExtensionFromUrl(file.toString()));
try{
Intent i;
i = new Intent(Intent.ACTION_VIEW);
i.setDataAndType(file,mimeType);
startActivity(i);
}catch (ActivityNotFoundException e) {
Toast.makeText(this,
"No Application Available to fiew this file type",
Toast.LENGTH_SHORT).show();
} https://stackoverflow.com/questions/10123227
复制相似问题