簡體   English   中英

Android - 從內部存儲文件夾中選擇文件

[英]Android - Select file from internal storage folder

我在內部存儲文件夾中保存了一堆視頻。 之后,我希望用戶能夠在此特定文件夾中選擇其中一個視頻。 我嘗試使用ACTION_GET_CONTENT試圖讓另一個應用程序為我這樣做,沒有任何成功,因為它只是在其他目錄中打開一個文件瀏覽器。

我現在擁有的是:

public static File getOwnVideosDirectory(Context context) {
    String ownVideosDirPath =
            context.getFilesDir().getAbsolutePath() + File.separator + "OwnVideos";
    File ownVideosDir = new File(ownVideosDirPath);
    if (!ownVideosDir.exists()) {
        ownVideosDir.mkdirs();
    }
    return ownVideosDir;
}

private void dispatchExistingVideo() {
    Log.d(LOG_TAG, "> dispatchExistingVideo");
    Intent videoPicker = new Intent(Intent.ACTION_GET_CONTENT);
    File ownVideosDir = Utility.getOwnVideosDirectory(getContext());
    videoPicker.setDataAndType(Uri.fromFile(ownVideosDir), "video/*");
    if (videoPicker.resolveActivity(getContext().getPackageManager()) != null) {
        startActivityForResult(videoPicker, REQUEST_EXISTING_VIDEO);
    }
}

所以我想知道,我做錯了什么,或者這樣做是不可能的。 如果不可能的話:是否有任何圖書館,...可以讓我做我想做的事情,或任何方向如何我自己作為最后的手段來實現這個?

提前致謝

請查看該庫 - Material File Picker
它允許使用.withPath(Utility.getOwnVideosDirectory(getContext()).getAbsolutePath())顯示具有指定路徑的對話框。

整個創作代碼:

new MaterialFilePicker()
    .withActivity(this)
    .withRequestCode(1)
    .withFilter(Pattern.compile(".*\\.txt$")) // Filtering files and directories by file name using regexp
    .withFilterDirectories(true) // Set directories filterable (false by default)
    .withHiddenFiles(true) // Show hidden files and folders
    .withPath(Utility.getOwnVideosDirectory(getContext()).getAbsolutePath())
    .start();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM