for getting the real path of capture image and gallery image the following code work perfectly fine for me.
private String getRealPathFromURI(Uri contentUri) {
        String result = null;
        try{
            String[] proj = { MediaStore.Images.Media.DATA };
            CursorLoader loader = new CursorLoader(requireActivity(), contentUri, proj, null, null, null);
            Cursor cursor = loader.loadInBackground();
            int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
            cursor.moveToFirst();
            result = cursor.getString(column_index);
            cursor.close();
        }catch(Exception e){
            Log.i("error_getting_path",e.getMessage());
        }
        return result;
    }
but in android 10 and above device i am not able to get the path of capture and gallery image . so my app is not working in android 10 and above for this feature. please suggest the best way to get path in all android devices.
 
    