簡體   English   中英

Java-如何在Android中選擇多個文件

[英]Java - How to pick multiple files in Android

我正在為Android(版本4.4)開發應用程序,並且試圖同時選擇多個文件(.doc,.pdf)。 目的是瀏覽目錄,選擇一些討厭的文件並返回這些文件的列表。 我最初已經嘗試過這種方式,但是Extra_Allow_Multiple指令不起作用:我一次只能選擇一個文件。

Intent intent = new Intent("com.sec.android.app.myfiles.PICK_DATA");
intent.putExtra("CONTENT_TYPE", "*/*");
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
intent.addCategory(Intent.CATEGORY_DEFAULT);
startActivityForResult(intent, PICKFILE_REQUEST_CODE);

因此,我嘗試了另一種方式,但是我沒有在設備的所有目錄中瀏覽,而是僅在特定目錄(圖像/視頻/音頻…)中瀏覽,並且由於相同的原因,我無法選擇多個文件。

Intent intent = new Intent();
intent.setType("*/*");
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(intent, PICKFILE_REQUEST_CODE);

我也嘗試了其他組合,但是經常出現類似以下錯誤:

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.GET_CONTENT (has extras) }

如何選擇多個文件(可能與第一種方法類似)?

你有嘗試過嗎?

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("file/*");
startActivityForResult(intent, PICKFILE_REQUEST_CODE);

我從這個 StackOverflow問題中提取了這段代碼。

我對Android中的此功能不是很熟悉,但是如果可以進一步幫助,顯然可以使用onActivityResult()檢索文件Uri

暫無
暫無

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

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