2011-04-20 61 views

回答

-1

使用AssetManager以获取PDF:

AssetManager assetManager = getAssets(); 
InputStream inputStream = assetManager.open("your_pdf.pdf"); 

,然后你可以写在卡:

File sdCard = Environment.getExternalStorageDirectory(); 
File dir = new File (sdcard.getAbsolutePath() + "/where/you/want/it"); 
dir.mkdirs(); 
File file = new File(dir, "your_pdf.pdf"); 
FileOutputStream f = new FileOutputStream(file); 

,并显示它

Uri path = Uri.fromFile(file); 
Intent intent = new Intent(Intent.ACTION_VIEW); 
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
intent.setDataAndType(path, "application/pdf"); 
startActivity(intent); 
+0

@本威廉姆斯不工作给filenotfoundexception权限拒绝。 – user386430 2011-04-20 21:38:59

+0

您需要''来编写。尝试调用'String [] files = assetManager.list()'并通过它来查看您的PDF是否显示。 – 2011-04-20 21:59:11

+0

@Ben Williams错误被修正仍然没有显示。我认为显示代码中的问题可以告诉我该怎么做 – user386430 2011-04-21 14:19:53

相关问题