Blankj / Blankj/AndroidUtilCode

Android 8.0 UriUtils.file2Uri 上存在转换问题

Open
#1,483 0 comments 0 reactions 1 assignee Claimed by @Blankj View on GitHub
bug
Dominant language
Java
Stars
33.6k
Forks
10.6k
PR merge metrics
No merged PRs in 30d

Description

## 描述 Bug

当我想在Android8.0上做文件共享时,把file转换为uri出现了问题

- AndroidUtilCode 的版本:com.blankj:utilcodex:1.30.4
- 出现 Bug 的设备型号:samsung s7
- 设备的 Android 版本:8.0

## 相关代码
```
UriUtils.file2Uri();
```
## 截图

正确转换后uriString应该是content://*****
![image](https://user-images.githubusercontent.com/19199353/115559132-fd8cb680-a2e5-11eb-8c07-ed8edc705a22.png)

在Android8.0转换如下图
![image](https://user-images.githubusercontent.com/19199353/115559268-24e38380-a2e6-11eb-947c-09ecbe6dc5b2.png)
我自己通过如下过时API转换一下可以了
```
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
//此处7.0要在图库更新完后才可以分享成功
try {
return Uri.parse(MediaStore.Images.Media.insertImage(MyApplication.AppContext.getContentResolver(), file.getAbsolutePath(), file.getName(), null));
} catch (FileNotFoundException e) {
e.printStackTrace();
return null;
}
} else {
return Uri.fromFile(file);
}
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.