android 跳转到系统相册选择图片

Intent intent = new Intent();

if (Build.VERSION.SDK_INT < 19) {
    intent.setAction(Intent.ACTION_GET_CONTENT);
    intent.setType("image/*");
} else {
    intent = new Intent(Intent.ACTION_PICK,MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    intent.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,"image/*");
}
activity.startActivityForResult(intent,1);

然后在onActivityForResult 拿到图片选择图片的路径:

 if (data != null){
                Uri selectedImage = data.getData();
                String[] filePathColumns = {MediaStore.Images.Media.DATA};
                Cursor c = getActivity().getContentResolver().query(selectedImage, filePathColumns, null, null, null);
                c.moveToFirst();
                int columnIndex = c.getColumnIndex(filePathColumns[0]);
                String imagePath = c.getString(columnIndex);
                imagePaths.add(imagePath);
                upLoadImage();
            }

你可能感兴趣的:(Android)