首页 > 解决方案 > TransactionTooLargeException when selecting many files using ACTION_GET_CONTENT intent

问题描述

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?

标签: androidfilechooser

解决方案


除了跳过之外,您没有办法限制用户做出的选择次数EXTRA_ALLOW_MULTIPLE

ACTION_GET_CONTENT实现(Android、设备制造商或应用程序开发人员)将选择的数量限制在不太可能导致问题的某个数量。显然,在您的设备上和这种情况下,ACTION_GET_CONTENT实现存在错误。如果您确定它是谁,请考虑提交错误报告。


推荐阅读