2016-12-22 23 views
0

我使用下面的代碼來打開我的應用程序創建的文件夾,但它不工作,雖然我從Trying open a specific folder in android using intent得到它打開特定文件夾。Android中與點擊

public void openFolder() { 
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); 
    String pa = sharedPreferences.getString("path", ""); 
    Intent intent = new Intent(Intent.ACTION_VIEW); 
    Uri uri = Uri.parse(pa); 
    intent.setDataAndType(uri, "*/*"); 
    startActivity(Intent.createChooser(intent, "Open folder")); 
} 

當我唱ACTION_VIEW,它顯示了一切可能的手段,除了FileManagerACTION_GET_CONTENT它把我帶到SAF模式都喜歡選擇儲存,然後特定的文件夾。

如何將它直接打開我的定義URI文件夾?有沒有其他方法?

+0

參考http://stackoverflow.com/questions/17165972/android-how-to-open-a-specific-folder-via-intent-and-show - 它的內容-IN-A-文件 – sasikumar

回答

0

這應該工作...

SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); 
String file= sharedPreferences.getString("path", ""); 
Intent intent = new Intent(Intent.ACTION_VIEW); 
intent.setDataAndType(Uri.fromFile(Environment.getExternalStorageDirectory().getPath() + file), "*/*"); 
startActivity(Intent.createChooser(intent, getString(R.string.open_folder))); 
+0

它是intent.setData給錯誤的要求作爲我們給字符串,而不是文件。 – Panache