Apps Copy Result of ACTION_GET_CONTENT to App Filedir


Oct 19, 2020
Recently I wanted to allow the user to pick a file and for internal reasons I have to copy it in to the Apps Directory (getFilesDir()). I let the User Pick any File with the Intent.ACTION_GET_CONTENT and the Type "*/*" so that the user really can pick anything.

From my Intent I mostly get a Uri around the lines of content:// and I copy these pretty easily like this:

Everything works wonderful if I get the scheme I said, but if I'm unlucky I get something along the lines content:// or any other android.providers.
Since these are obviously not a real file, because they don't have any filetype, I'm at a loss how to copy them. I have found a Function ( that gives me the real Path, but every time I try to copy with that Path I get a Permission Denied Error, even though I ask for write and read external Storage permissions and the user allows them to me. So how would it be better to copy the files?