android 获取缩略图路径,android – 获取图像缩略图文件路径

我正在尝试获取thumnail路径,而不是位图对象.

当我查询这些时,由于某种原因,某些缩略图路径为空.

(我的设备中有1028个缩略图,光标长度确实是1028,但仍然返回空值)我知道有1028个缩略图,因为我查了一下.

这是我的代码:

String[] projection = {MediaStore.Images.Thumbnails._ID};

// Create the cursor pointing to the SDCard

cursor = this.getContentResolver().query( MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,

projection, // Which columns to return

null, // Return all rows

null,

MediaStore.Images.Thumbnails.IMAGE_ID);

// Get the column index of the Thumbnails Image ID

Log.d(Global.TAG, "BEFORE");

columnIndex = cursor.getColumnIndex(MediaStore.Images.Thumbnails._ID);

Log.d(Global.TAG, "AFTER1");

for(int i =0;i

cursor.moveToPosition(i);

Log.d("MyTag","BBABA" + i +" : " + getThumbnailPathForLocalFile(cursor.getLong(columnIndex)));

}

cursor.close();

我的getThumbnailPathForLocalFile:

String getThumbnailPathForLocalFile(long fileId)

{

// Log.d(Global., msg)

Cursor thumbCursor = null;

try

{

thumbCursor = this.getContentResolver().

query(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI

, null

, MediaStore.Images.Thumbnails.IMAGE_ID + " = " + fileId+ " AND "

+ MediaStore.Images.Thumbnails.KIND + " = "

+ MediaStore.Images.Thumbnails.MINI_KIND , null, null);

if(thumbCursor.moveToFirst())

{

// the path is stored in the DATA column

int dataIndex = thumbCursor.getColumnIndexOrThrow( MediaStore.MediaColumns.DATA );

String thumbnailPath = thumbCursor.getString(dataIndex);

return thumbnailPath;

}

}

finally

{

if(thumbCursor != null)

{

thumbCursor.close();

}

}

return null;

}

检查后,我发现我发送的ID就像for循环的索引一样.

我甚至不确定我的代码应该工作,所以任何其他代码都会很棒.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值