且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

尝试从图片中读取元数据时获取FileNotFoundException(权限被拒绝)

更新时间:2021-07-04 10:25:49

从策略上看,您似乎没有READ_EXTERNAL_STORAGE权限,该权限

Tactically, it would appear that you do not have the READ_EXTERNAL_STORAGE permission, which you need to request in the manifest and at runtime.

除此之外:

  • 您的query()无需返回DATA

不要求DATA列具有值

不要求DATA列具有文件系统路径

There is no requirement that the DATA column have a filesystem path

即使READ_EXTERNAL_STORAGE

特别是,可以确保您的代码在Android Q上失败,并且在许多其他设备上的许多用户也很可能失败.

In particular, it is guaranteed that your code will fail on Android Q, and it is very likely to fail for lots of users on lots of other devices as well.

Uri(imageUri)与ContentResolver一起使用,以获取InputStream(或者可能是FileDescriptor)传递给您的库.

Use the Uri (imageUri) with ContentResolver to get an InputStream (or perhaps a FileDescriptor) to pass to your library.