2014-12-27 88 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"); 
} 
相关问题