Targeting API 24 or above, instead of using a simple \"Uri.fromFile\" command, developers need to use FileProvider (or their own ContentProvider), in order
A Uri
is not a file. You are calling getPath()
on a Uri
and are treating it as if it were a file path. That only works if the scheme in the Uri
is file
. In your case, it is not.
You already have a File
object pointing to the file. It is called photoFile
. Hold onto that in a field of your activity, and save it in the saved instance state Bundle
(as your process might get terminated while the camera app is in the foreground). Then, use photoFile
. Don't use the built-in ExifInterface
though, as it has security flaws.
How do I get the orientation using the above code (or even a better code), using the new FileProvider Uri ?
You don't. Use photoFile
.
Maybe I can force the ContentResolver to use the previously ContentProvider to get the needed column's data of the cursor?
I have no idea why you would expect the getOrientation()
that takes a Uri
to work. You are querying the MediaStore
for data about a Uri
that does not come from the MediaStore
.
Do I really have to create my own ContentProvider here?
No, because FileProvider
is not your problem. You would have the same flawed getOrientation()
methods with your own ContentProvider
.