private void UpdateLatestPhotos() { Cursor c = Media.Query(this.mContext.ContentResolver, Media.ExternalContentUri, new string[] { "_id", "datetaken", "_size" }, (string)null, (string[])null, "date_added DESC"); if (c != null) { try { int count = 0; this.mRecentlyUpdatedPhotos = new System.Collections.Generic.List <PhotoContent>(); while (c.MoveToNext()) { MediaStoreCompat.PhotoContent item = new MediaStoreCompat.PhotoContent { id = c.GetLong(0), taken = c.GetLong(1), size = c.GetInt(2) }; this.mRecentlyUpdatedPhotos.Add(item); ++count; if (count > 5) { break; } } } finally { c.Close(); } } }
private Uri FindPhotoFromRecentlyTaken(File file) { if (this.mRecentlyUpdatedPhotos == null) { this.UpdateLatestPhotos(); } long fileSize = file.Length(); long taken = ExifInterfaceCompat.GetExifDateTimeInMillis(file.AbsolutePath); int maxPoint = 0; MediaStoreCompat.PhotoContent maxItem = null; foreach (var item in this.mRecentlyUpdatedPhotos) { int point = 0; if ((long)item.size == fileSize) { ++point; } if (item.taken == taken) { ++point; } if (point > maxPoint) { maxPoint = point; maxItem = item; } } if (maxItem != null) { this.GenerateThumbnails(maxItem.id); return(ContentUris.WithAppendedId(Media.ExternalContentUri, maxItem.id)); } else { return(null); } }