Jayaprakash7
7/28/2017 - 6:22 AM

Get the Image From gallery

Get the Image From gallery

public String getPathFromURI(Uri contentUri)
{
        String res = null;
        String[] proj = {MediaStore.Images.Media.DATA};
        Cursor cursor = getActivity().getContentResolver().query(contentUri, proj, null, null, null);
        if (cursor.moveToFirst()) {
            int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
            res = cursor.getString(column_index);
        }
        cursor.close();
        return res;
    }
    
public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode == Activity.RESULT_OK) {
            if (requestCode == SELECTED_PICTURE) {
                // Get the url from data
                Uri selectedImageUri = data.getData();
                if (null != selectedImageUri) {
                    // Get the path from the Uri
                    String path = getPathFromURI(selectedImageUri);
                    Log.i("Upload Image", "Image Path : " + path);
                    // Set the image in ImageView
                    imageUpload.setImageURI(selectedImageUri);
                }
            }
        }
    }


    
 if (v.getId() == R.id.image_upload){
                openImageChooser();
            }