2011-04-20 62 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

相關問題