0

If you open an FileChooser using Intent.ACTION_GET_CONTENT and select a huge amount of files e.g. 2500, a TransactionTooLargeException will be thrown and then the process is killed without resuming in onActivityResult:

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
        intent.addCategory(CATEGORY_OPENABLE);
        intent.setType("*/*");
        intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
        intent = Intent.createChooser(intent, "Foo");
        startActivityForResult(intent, 121);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        // logic stuff
    }
}

How is it possible to let the user decide how many files to select without destroying the app?

Jules
  • 189
  • 1
  • 5
  • 20

1 Answers1

1

You do not have a means of limiting the number of selections that the user makes, other than to skip EXTRA_ALLOW_MULTIPLE.

It is up to the ACTION_GET_CONTENT implementation (Android, device manufacturer, or app developer) to limit the number of selections to some number that is unlikely to cause problems. Apparently, on your device and for this scenario, the ACTION_GET_CONTENT implementation has a bug. If you know for certain whose it is, consider filing a bug report.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491