Reputation: 13
I want to programmatically load multiple photos (say the latest 20 by date) with Xamarin.Android, without a user's interaction (i.e. not manually pick photos from a displayed collection).
Is it possible do this? Any sample code that I may use?
BTW, I know the code below, but that requires a user to pick a photo:
intent.SetType("image/*");
intent.SetAction(Intent.ActionGetContent);
MainActivity.Instance.StartActivityForResult(...);
Upvotes: 0
Views: 69
Reputation: 18861
You can use MediaStore to get the path of image .
Android.Net.Uri mImageUri = MediaStore.Images.Media.ExternalContentUri;
ContentResolver mContentResolver = ContentResolver;
var mCursor = mContentResolver.Query(mImageUri, null,
MediaStore.Images.ImageColumns.MimeType + "=? or "
+ MediaStore.Images.ImageColumns.MimeType + "=?",
new String[] { "image/jpeg", "image/png" }, MediaStore.Images.ImageColumns.DateModified);
while (mCursor.MoveToNext())
{
var imagePath = mCursor.GetString(mCursor.GetColumnIndex(MediaStore.Images.ImageColumns.Data));
// do something you want
}
Upvotes: 1