我在将视频URI转换为文件时遇到问题。当我尝试获取“真实”路径时,该路径将为null。
从图库中获取视频就像魅力一样:
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
this.context?.let {
data.run {
}.let {
val videopath = UploadVideoHandler().getRealPathFromURI(data.data, this.activity)
}
}
}
但是这个不想和我一起玩, s 一直都只返回null ...
public String getRealPathFromURI(Uri contentURI, Activity context) {
String[] projection = { MediaStore.Video.Media.DATA };
@SuppressWarnings("deprecation")
Cursor cursor = context.managedQuery(contentURI, projection, null,
null, null);
if (cursor == null)
return null;
int column_index = cursor
.getColumnIndexOrThrow(MediaStore.Video.Media.DATA);
if (cursor.moveToFirst()) {
String s = cursor.getString(column_index);
// cursor.close();
return s;
}
// cursor.close();
return null;
}