Skip to content
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

封装了一个函数 能完美获取真实文件路径兼容各种机型 #2882

Open
qianmohunchen opened this issue Apr 10, 2024 · 1 comment

Comments

@qianmohunchen
Copy link

Current use version?

当前使用的版本是多少?3.11.2


Will this problem occur in demo?

Demo能否复现这问题?


Describe the problem or provide an error log?

描述问题或提供错误log?


3.11.2的版本
fun getPath2(context: Context, localMedia: LocalMedia): String? {
val path = localMedia.path ?: localMedia.realPath
return if (!path.isNullOrEmpty() && path.startsWith("content://")) {
val uri = Uri.parse(path)
PictureFileUtils.getPath(context, uri)
} else {
path
}
}

@ccclll1990
Copy link

ccclll1990 commented Apr 17, 2024

    String path = "";
    if (!TextUtils.isEmpty(media.getCompressPath())) {
        path = media.getCompressPath();
    } else {
        if (!TextUtils.isEmpty(media.getPath()) && media.getPath().startsWith("content:")) {
            Uri uri = Uri.parse(media.getPath());
            path = PictureFileUtils.getPath(context, uri);
        } else {
            path = media.getRealPath();
        }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants