How to get orientation of image file, which was taken from FileProvider class?

前端 未结 1 1186
粉色の甜心
粉色の甜心 2021-01-21 03:21

Background

Targeting API 24 or above, instead of using a simple \"Uri.fromFile\" command, developers need to use FileProvider (or their own ContentProvider), in order

1条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-21 03:48

    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.

    0 讨论(0)
提交回复
热议问题