如何判斷檔案呢? 可以通過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;
}