【发布时间】:2021-02-19 18:08:11
【问题描述】:
当我打开图库并转到保管箱或一个驱动器时,我收到一条消息无法获取路径,但是当我转到 google 照片或本地时,我得到了正确的图像以加载到网格中。
DependencyService.Get<IMediaService>().OpenGallery();
MessagingCenter.Unsubscribe<App, List<string>>((App)Xamarin.Forms.Application.Current, "ImagesSelectedAndroid");
MessagingCenter.Subscribe<App, List<string>>((App)Xamarin.Forms.Application.Current, "ImagesSelectedAndroid", (s, images) =>
{
if (images.Count > 0)
{
Console.WriteLine($"Processed {images.Count} images");
UploadToBlob(images);
GetGallery();
}
public void OpenGallery()
{
try
{
var imageIntent = new Intent(Intent.ActionPick);
imageIntent.SetType("image/*");
imageIntent.PutExtra(Intent.ExtraAllowMultiple, true);
imageIntent.SetAction(Intent.ActionGetContent);
((Activity)CrossCurrentActivity.Current.Activity).StartActivityForResult(Intent.CreateChooser(imageIntent, "Select photo"), Opengallerycode);
Toast.MakeText(CrossCurrentActivity.Current.Activity, "Tap and hold to select multiple photos.", ToastLength.Short)?.Show();
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
Toast.MakeText(CrossCurrentActivity.Current.Activity, "Error. Can not continue, try again.", ToastLength.Long)?.Show();
}
}
【问题讨论】:
-
如何使用
GetGallery方法获取图库? -
我刚刚添加了我创建的 opengallery 类来打开它。
-
我建议使用流而不是路径来获取图像。
标签: android xamarin dropbox imagepicker