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\").
Replace %20 with space like below
filePath = filePath.replaceAll("%20"," ");
This worked for me