Android10 上 item.isUriPath 判断错误问题
lzan13 opened this issue · 6 comments
lzan13 commented
debug 看了下,在 Android10 上返回的是 false,看源码判断是根据 path 判断的,但是 path获取的是真实路径,不包含 content://, getUri 是根据 uriPath 解析的,这里才是包含 content://,所以这里是不是应该改下
public boolean isUriPath() {
return path != null && path.contains("content://");
}
public Uri getUri() {
if (uriPath != null && uriPath.length() > 0) {
return Uri.parse(uriPath);
}
if (isUriPath()) {
return Uri.parse(path);
}
return PBitmapUtils.getContentUri(mimeType, id);
}
yangpeixing commented
你好,感谢你提出此建议,目前android10上ImageItem的path代表绝对路径,Uri路径需要读取Uripath,因为在android10上可能某些设备获取不到path绝对路径(走异常),此时的path就会读取uripath的值,因为无论在什么版本的android系统上都能获取到uri路径,item.isUriPath仅仅是判断当前path是否为uri路径,uripath理论上都会有值
yangpeixing commented
imageItem里包含两个字段,
path:绝对路径,在android10上读取不到绝对路径的情况下,代表uriPath,通过item.isUriPath判断
uriPath:Uri路径,以content开头,理论上只要从数据库读取,此字段都会有值
isUriPath:判断当前path字段是否是uri路径
yangpeixing commented
lzan13 commented
哦哦,感谢解释,了解了
FynnJason commented
同样遇到了这个问题,以为低于10版本使用path,10以上使用uri,但是通过以下代码是走的false
if (it[0].isUriPath) {
logE("true")
GlideApp.with(this)
.load(it[0].uri)
.into(iv_info_head)
} else {
logE("false")
GlideApp.with(this)
.load(it[0].path)
.into(iv_info_head)
}
FynnJason commented
所以不论哪个版本,都直接使用uri吗