Get image Uri in onActivityResult after taking photo?

后端 未结 4 726
逝去的感伤
逝去的感伤 2021-02-07 00:48

I have this code:

startActivityForResult(new Intent(MediaStore.ACTION_IMAGE_CAPTURE), CAMERA_IMAGE);

That allows that user to take a photo. Now

4条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-07 01:13

    protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
        if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) {
    
              Bitmap photo = (Bitmap) data.getExtras().get("data");
              Uri fileUri = Utils.getUri(getActivity(), photo);
        }  
    }
    
    public String getRealPathFromURI (Uri contentUri) {
        String path = null;
        String[] proj = { MediaStore.MediaColumns.DATA };
        Cursor cursor = getActivity().getContentResolver().query(contentUri, proj, null, null, null);
        if (cursor.moveToFirst()) {
            int column_index = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA);
            path = cursor.getString(column_index);
        }
        cursor.close();
        return path;
    }
    

提交回复
热议问题