As written in that code snippet, it returns the path if it is available. There are many cases where the path will not be available. Each content provider can return any URI it likes.
The extension in the URI might be relevant and might not be relevant.
It will also behave in different ways between different devices and different OS versions.
The bottom line is that you should solve it in a different way. Ask the user which type of files they are looking for and limit ContentChooser based on that.