[使用ACTION_GET_CONTENT目的选择许多文件时的TransactionTooLargeException

问题描述 投票:0回答:1

如果您使用Intent.ACTION_GET_CONTENT打开FileChooser并选择大量文件,例如2500,将抛出TransactionTooLargeException,然后终止该进程,而无需在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
    }
}

如何让用户决定要选择多少个文件而不破坏应用程序?

android filechooser
1个回答
1
投票

除了跳过EXTRA_ALLOW_MULTIPLE,您没有限制用户进行选择的数量的方法。

取决于ACTION_GET_CONTENT实现(Android,设备制造商或应用程序开发人员),将选择的数量限制为不太可能引起问题的数量。显然,在您的设备上并且对于这种情况,ACTION_GET_CONTENT实现存在一个错误。如果您确定是谁,请考虑提交错误报告。

© www.soinside.com 2019 - 2024. All rights reserved.