Android获取SD卡上图片和视频缩略图的小例子
如何判断文件呢? 可以通过cursor遍历数据库,对比internal_content_uri字段的值,这是一个uri,这里保存着android手机sd卡上的多媒体文件完整路径。
[java]
uri originaluri = mediastore.images.media.external_content_uri;
//若为视频则为mediastore.video.media.external_content_uri;
contentresolver cr = this.getcontentresolver();
cursor cursor = cr.query(originaluri, null, null, null, null);
if (cursor == null) {
return;
}
for (cursor.movetofirst();!cursor.isafterlast(); cursor.movetonext()) {
long thumbnailsid = cursor.getlong(cursor .getcolumnindex("_id"));
bitmap bitmap = mediastore.images.thumbnails.getthumbnail(cr,
thumbnailsid, video.thumbnails.micro_kind, null);
//若为视频则为
// bitmap bitmap = mediastore.video.thumbnails.getthumbnail(cr,
// thumbnailsid, video.thumbnails.micro_kind, null);
return bitmap;
}
uri originaluri = mediastore.images.media.external_content_uri;
//若为视频则为mediastore.video.media.external_content_uri;
contentresolver cr = this.getcontentresolver();
cursor cursor = cr.query(originaluri, null, null, null, null);
if (cursor == null) {
return;
}
for (cursor.movetofirst();!cursor.isafterlast(); cursor.movetonext()) {
long thumbnailsid = cursor.getlong(cursor .getcolumnindex("_id"));
bitmap bitmap = mediastore.images.thumbnails.getthumbnail(cr,
thumbnailsid, video.thumbnails.micro_kind, null);
//若为视频则为
// bitmap bitmap = mediastore.video.thumbnails.getthumbnail(cr,
// thumbnailsid, video.thumbnails.micro_kind, null);
return bitmap;
}
上一篇: jQuery大于号(>)选择器的作用解释