2015-10-20 171 views
0

我有下面的代碼在Android中打開一個文件夾,雖然我看到很多帖子提到它的作品,我無法得到它的工作。Android:打開文件夾對話框

Intent intent = new Intent(Intent.ACTION_GET_CONTENT); 
File f = new File(Environment.getExternalStorageDirectory(),"myFolder"); 
Uri uri = Uri.fromFile(f); 
intent.setDataAndType(uri, "*/*"); 
startActivity(Intent.createChooser(intent, "Open folder")); 

它只是打開根文件夾(在這種情況下,/ storage/sdcard而不是/ storage/sdcard/myfolder)。

任何人都知道爲什麼?

感謝

回答

1

ACTION_GET_CONTENTdocumented使用一個IntentUri部分。雖然可能有一些應用程序的活動支持ACTION_GET_CONTENT,但許多應用程序不會。

此外,Android並不真正適用於「文件夾」,因此在設備上不一定會有任何應用程序,它可以讓您瀏覽任意東西。

歡迎您在Android 4.4+上使用the Storage Access Framework,這是Google處理用戶瀏覽多個來源內容的中央系統UI的方法。或者file and directory picker libraries for Android