我正在使用Android studio ...我想給1個特定目錄的訪問給用戶...內部目錄... 是否可以使用環境設置路徑..Please幫助如何讓用戶訪問Android中的內部目錄
String path= //if possible the environment
感謝
我正在使用Android studio ...我想給1個特定目錄的訪問給用戶...內部目錄... 是否可以使用環境設置路徑..Please幫助如何讓用戶訪問Android中的內部目錄
String path= //if possible the environment
感謝
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);
我通常使用下面的內部存儲:
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);
請解釋什麼是「給1個特定目錄的訪問權限的用戶」的意思。另外,請說明「使用環境設置路徑」的含義。 – CommonsWare
@CommonsWare我的意思是我想讓我的應用程序能夠訪問內部 目錄,例如-_ @ drawable_,他們可以瀏覽它們..如果它是一個圖像,我希望它們能夠像查看它們一樣查看它們gallery。&由路徑集合我只是說我想要一個環境的字符串路徑..希望你能幫助 – Anonymous
「eg- @ drawable的內部目錄」 - 這不是設備上的目錄。它只是你開發機器上的一個目錄。 – CommonsWare