从id android获取文件路径

时间:2014-05-01 09:13:03

标签: android

我正在使用此代码获取android中所有视频的路径

ContentResolver cr = getContentResolver();
String[] proj = {
                BaseColumns._ID
};

Cursor c = cr.query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, proj, null, null, null);
if (c.moveToFirst()) {
    do
    {
        int id = c.getInt(0);
        Bitmap b = MediaStore.Video.Thumbnails.getThumbnail(cr, id, MediaStore.Video.Thumbnails.MINI_KIND, null);
        Log.d("*****My Thumbnail*****", "onCreate bitmap " + b);
        ImageView iv = (ImageView) findViewById(R.id.img_thumbnail);
        iv.setImageBitmap(b);
    }
    while( c.moveToNext() );
}         
c.close();

但是我得到了一些身份证号码。我想要真实的uri文件或内容uri。如何获得它?

1 个答案:

答案 0 :(得分:1)

试试这个:

ContentResolver cr = getContentResolver();
String[] proj = {
MediaStore.Video.Media._ID,
MediaStore.Video.VideoColumns.DATA
};

...

String ID = c.getLong(c.getColumnIndexOrThrow(MediaStore.Video.VideoColumns._ID));
String  DATA_URI = Uri.parse(c.getString(c.getColumnIndexOrThrow(MediaStore.Video.VideoColumns.DATA)));