My code works correctly while opening a file in sdcard. However, if I open a filename with white space then error occurs (example: Path - \"/sdcard/download/hello hi.jpg\").
Try:
Uri uri = Uri.parse(paths);
File file = new File(uri.getPath());
Uri.parse
fixes all the whitespace/backslash/illegal character issues in paths and produces a "good" uri.
Replace %20 with space like below
filePath = filePath.replaceAll("%20"," ");
This worked for me
You need to escape the spaces. Try replacing " " with "\ "