如果您的应用支持 sdk 版本 JELLY_BEAN_MR2。最好像这样打开意图,
Intent intent;
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN_MR2) {
intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
intent.setType("image/*");
} else {
intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("image/*");
}
checkAndStartActivityForResult(intent, RESULT_LOAD_IMAGE);
private void checkAndStartActivityForResult(Intent intent, int requestCode) {
//Open only if any intent can be handled from some component
if (intent.resolveActivity(getActivity().getPackageManager())!=null) {
startActivityForResult(createChooser(intent, ""), requestCode);
}else{
//show error to user
}
}