小编Mer*_*lez的帖子

使用Intent.ACTION_GET_CONTENT选择多个文件

我正在尝试用Intent选择多个文件,但似乎我缺少某些东西.
我创建了一个Intent.ACTION_GET_CONTENT Intent,将Intent.EXTRA_ALLOW_MULTIPLE作为额外的
(它似乎完全符合目的)并创建一个选择器(可选),它选择应该能够选择多个文件并返回它们的应用程序.

问题是我只能选择一个文件.

我试过多个文件浏览器.这是API 18(4.3).

ACTIVITY_CHOOSE_FILE = 1;  //global constant
Button btn = (Button) this.findViewById(R.id.btnGetFiles);
btn.setOnClickListener(new OnClickListener() {
  @Override  
  public void onClick(View v) {  
    Intent chooseFile;  
    Intent intent;  
    chooseFile = new Intent(Intent.ACTION_GET_CONTENT);  
    chooseFile.setType("file/*");  
    chooseFile.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);  
    intent = Intent.createChooser(chooseFile, "Choose a file");  
    startActivityForResult(intent, ACTIVITY_CHOOSE_FILE);  
  }  
});
Run Code Online (Sandbox Code Playgroud)

我还将此添加到Manifest(它在添加之前具有相同的功能):

        <intent-filter>
            <action android:name="android.intent.action.GET_CONTENT" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>  
Run Code Online (Sandbox Code Playgroud)

为什么我不能选择多个文件?
(澄清:问题不在于,多个文件没有返回 - 我不能选择多个文件)

android android-intent

19
推荐指数
5
解决办法
1万
查看次数

标签 统计

android ×1

android-intent ×1