-
Notifications
You must be signed in to change notification settings - Fork 156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🔥 【置顶】获取路径为空的问题(Path return null problem) #49
Comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
图片压缩的时候,传入 Uri ,会有部分图片返回的 Uri 为空,这个问题要怎么解决 |
参考方法👉 |
可以看下这篇文章 Android通过uri获取文件路径 |
他的解决方式是把 和上面原理相同的还有另外一种方式: https://github.com/coltoscosmin/FileUtils/blob/master/FileUtils.java 也可以解决路径为空的问题: 之所以后面删掉这种方式是因为它对于处理小文件和少量文件时还可以, 一旦文件过大或数量多的话就会严重占用手机存储, 所以建议尽量用uri操作文件而不是直接使用path。 当然万不得已的情况下不失为一种解决方式。 |
我现在的场景就是必须得获取到真实路径,单从不能出问题的角度来看,这个方法不失为暂时的解决之策。还有就是那个 FileSelector的构建能不能改改啊,以及示范例子给多点,点进去看源码才知道,还要处理回调。。。 |
✨基本上每一个
issue
都会提到的问题👉Android Q及以上版本获取路径为空🌴测试环境
API 30 , Android 11.0
Video_2021-09-07_155012.convert-video-online.com.mp4
🍎 可以看到, 同一文件会有两种不同的 Uri :
手机图标
进入时获取到文件的Uri
为content://com.android.externalstorage.documents/...
,此时路径不为空;Download
进入时Uri
为content://com.android.providers.downloads/...
, 此时路径为空。🌴建议使用
Uri
替换Path
, 如上传文件操作可以使用ContentResolver.openInputStream/openFile/...
等API操作, 唯一缺点是不能显示文件路径, 但不会影响功能使用。The text was updated successfully, but these errors were encountered: