@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
// TODO 选择视频回调
case ProfilePhotoTask.PHOTO_CAMERA:
if (resultCode == Activity.RESULT_OK) {
try {
Uri uri = data.getData();
uri = BitmapCache.geturi(this, data);
//在这里小米手机回调中uri格式为:file:///···,不需要通过Cursor获取path
File file=null;
if(uri.toString().indexOf("file")==0){
file = new File(new URI(uri.toString()));
path = file.getPath();
}else{
path = getPath(uri);
file = new File(path);
}
if (!file.exists()) {
break;
}
if (file.length() > 100 * 1024 * 1024) {
commonToast("文件大于100M");
break;
}
submitVedio();
} catch (Exception e) {
String a=e+"";
} catch (OutOfMemoryError e) {
String a=e+"";
}
}
break;
}
}
小米手机获取视频文件uri后获取Cursor为null,此处不知道是为什么。但是小米手机回调的uri格式为file:///···所以可以直接转化为file.
private String getPath(Uri uri) {
String[] projection = {MediaStore.Video.Media.DATA};
Cursor cursor = managedQuery(uri, projection, null, null, null);
int column_index = cursor
.getColumnIndexOrThrow(MediaStore.Video.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}