80,356
社区成员
发帖
与我相关
我的任务
分享
Intent intent = new Intent("android.intent.action.GET_CONTENT");
//intent.setType("image/jpeg");
intent.setType("image/*");
//打开系统相册
startActivityForResult(intent, REQUEST_IMAGE_GET);
//方法,相册选取
//在 MainActivity 中的调用方法:clsTakePhotoSelectImg.mSelectImage(MainActivity.this);
public static void mSelectImage(Activity praActivity) {
Intent intent = new Intent("android.intent.action.GET_CONTENT");
//这种方法,闪退
//所有图片格式:intent.setType("image/*");
//String[] mimeTypes = {"image/jpg", "image/jpeg"};
//intent.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes);
String[] supportedMimeTypes = {"image/jpg", "image/jpeg"};
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
intent.setType(supportedMimeTypes.length == 1 ? supportedMimeTypes[0] : "*/*");
if (supportedMimeTypes.length > 0) {
intent.putExtra(Intent.EXTRA_MIME_TYPES, supportedMimeTypes);
}
} else {
String mimeTypes = "";
for (String mimeType : supportedMimeTypes) {
mimeTypes += mimeType + "|";
}
intent.setType(mimeTypes.substring(0,mimeTypes.length() - 1));
}
//打开系统相册
praActivity.startActivityForResult(intent, REQUEST_IMAGE_GET);
}