2014-12-27 87 views
-1

我想直接路徑到assets文件夾,以便打開存儲在那裏的PDF。 這樣我就可以把它作爲在這個意圖參數:如何獲取資產文件夾的直接路徑

Intent i = new Intent(this, SecondMainActivity.class); 
i.putExtra(PdfViewerActivity.EXTRA_PDFFILENAME, "path_to_assets_folder"); 
startActivity(i); 
+0

您發佈了很多問題,但從未贊成或標記任何答案爲正確的,這種行爲會阻止他人回答您的問題。 – 2015-01-08 18:01:25

+0

對不起,但那是因爲答案不適合我 – Bouss 2015-01-09 00:36:33

+0

你能解釋爲什麼這些答案不工作嗎? – 2015-01-09 01:59:05

回答

0

試試這個;

Intent intent = new Intent(Intent.ACTION_VIEW); 
intent.setDataAndType(Uri.parse("file://" + getFilesDir() + "/yourfile.pdf"), 
       "application/pdf"); 
startActivity(intent); 

你也可以檢查此:Read a pdf file from assets folder

0

Android Developer guide

public final AssetManager getAssets() 

Added in API level 1 
Retrieve underlying AssetManager storage for these resources. 

的話,你可以使用getAssets

AssetManager mngr = getAssets(); 

assets文件夾訪問一個文件,

InputStream is = mngr.open("file name"); 

如果你的課程不是Activity,你需要傳遞一個上下文,然後調用getAssets

public myClass(Context myContext) { 
    AssetManager mngr = myContext.getAssets(); 
    InputStream is = mngr.open("file name"); 
} 
相關問題