【发布时间】:2014-01-17 12:25:56
【问题描述】:
在我的应用程序中,我启动了一个 Intent 来选择这样的视频文件
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("video/*");
startActivityForResult(intent, kVideoPickerRequestCode);
当它回来时,我得到这样的 Uri:
if(resultCode == RESULT_OK) {
if (requestCode == kVideoPickerRequestCode) {
Uri selectedVideoURI = data.getData();
}
}
这个 Uri 似乎适合我的 VideoView。它完美地播放挑选的视频。但现在我想将视频上传到服务器,因此需要一个文件。
无论我如何尝试将 Uri 转换为 String-Path,它都失败了......我读了一些关于这个的 SO 帖子 How to convert content:// Uri into actual file path? 要么 FileNotFoundException when trying to upload a recorded video to server from Android app 但这对我不起作用。
这样的代码总是返回 NULL 作为路径:
public static String getRealPathFromUri(Activity activity, Uri contentUri) {
String[] proj = { MediaStore.Images.Media.DATA };
Cursor cursor = getActivity().getContentResolver().query(uri, proj, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
我的测试设备运行的是 Android 4.4.2。会不会是 KitKat 的一些安全问题?
感谢任何帮助提示!
【问题讨论】:
标签: android security video uri android-4.4-kitkat