我想从图库中选择照片,但是从下面编码显示带有SD卡外部应用程序的图库,例如前Astro Manager。我想它应该只向我展示Gallery而不是其他第三方应用程序或与那些东西相关等。
虚拟代码,其中列出了可以像Astro Manager等一样浏览的所有应用程序。
Intent intent=new Intent();
intent.setType("image/*");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"),10);
答案 0 :(得分:3)
你的代码是正确的,但你需要我的帮助。只需查看链接,它就可以帮助您处理图库Link
对于您的任务,您可以添加此示例代码
Intent i = new Intent(
Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, RESULT_LOAD_IMAGE);
答案 1 :(得分:0)
试试这个 -
private static final int PICTURE_GALLERY = 1;
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(photoPickerIntent, PICTURE_GALLERY);
答案 2 :(得分:0)
如果您的应用支持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
}
}