2016-09-26 31 views
1

我正在使用Android studio ...我想給1個特定目錄的訪問給用戶...內部目錄... 是否可以使用環境設置路徑..Please幫助如何讓用戶訪問Android中的內部目錄

String path= //if possible the environment 

感謝

+1

請解釋什麼是「給1個特定目錄的訪問權限的用戶」的意思。另外,請說明「使用環境設置路徑」的含義。 – CommonsWare

+0

@CommonsWare我的意思是我想讓我的應用程序能夠訪問內部 目錄,例如-_ @ drawable_,他們可以瀏覽它們..如果它是一個圖像,我希望它們能夠像查看它們一樣查看它們gallery。&由路徑集合我只是說我想要一個環境的字符串路徑..希望你能幫助 – Anonymous

+0

「eg- @ drawable的內部目錄」 - 這不是設備上的目錄。它只是你開發機器上的一個目錄。 – CommonsWare

回答

0
File file = new File(context.getFilesDir() + "/" + filename); 

會返回一個文件中的內部目錄。如果你的類擴展Activity嘗試

String path = context.getFilesdir(); 
System.out.println("Internal directory path: " + path); 

String path = this.getFilesdir(); 
System.out.println("Internal directory path: " + path); 
+0

謝謝@Spectre我會嘗試它,讓你知道它是否工作 – Anonymous

+0

它會! :)無可能 – 2016-09-26 13:10:01

+0

它顯示getFilesDir()的錯誤不能從靜態上下文中引用並且該變量文件從不使用 – Anonymous

0

我通常使用下面的內部存儲:

ContextWrapper cw = new ContextWrapper(mContext); 
File fileDownloadFolder = cw.getDir(Environment.DIRECTORY_DOWNLOADS, Context.MODE_PRIVATE); 

File file = new File(fileDownloadFolder.getAbsolutePath()+"/"+ filename); 

使用此得到您的路徑在這個例子中,返回一個名爲filename的文件,位於文件夾Downloads中他在內部存儲的App文件夾。

而對於外部存儲使用:

File fileDownloadFolder = getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS); 
File file = new File(fileDownloadFolder.getAbsolutePath()+"/"+ filename);