从本地存储中获取视频路径时,始终在游标对象中获取空值
public String getPath(Uri uri){
Log.i(TAG,"inside getpath");
String[] filePathColumn={MediaStore.Video.Media.DATA};
Cursor cursor=getContentResolver().query(uri, filePathColumn, null, null, null);
Log.i(TAG,"bloody cursor = "+cursor);if (cursor != null) {
// HERE YOU WILL GET A NULLPOINTER IF CURSOR IS NULL
// THIS CAN BE, IF YOU USED OI FILE MANAGER FOR PICKING THE MEDIA
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA);
cursor.moveToFirst();
Log.i(TAG,"exit if get path");
return cursor.getString(column_index);
} else{
Log.i(TAG,"exit else get path");
return null;
}
}
错误记录如下:
03-11 15:10:04.415 1758-1758/com.example.vivekgandhi.playvideoapp I/MyMessage: bloody cursor = null
03-11 15:10:04.415 1758-1758/com.example.vivekgandhi.playvideoapp I/MyMessage: exit else get path