对于本地视频,Cursor始终返回NULL以从文件资源管理器中获取路径

时间:2017-03-11 09:42:43

标签: android

从本地存储中获取视频路径时,始终在游标对象中获取空值

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

0 个答案:

没有答案