[英]How to select multiple images from gallery for android and iOS device using xamarin.forms?
I am working on xamarin.forms. 我正在研究xamarin.forms。 I am creating an app that can run on Android and iOS both.
我正在创建一个可以在Android和iOS上运行的应用程序。 I have to select multiple images from gallery for both devices.
我必须从两个设备的库中选择多个图像。
But, I am unable to select multiple images at a time. 但是,我无法一次选择多个图像。 I can select single image with help of media picker (
CrossMedia
). 我可以借助媒体选择器(
CrossMedia
)选择单个图像。
Please update me how I can select multiple images from gallery for both devices using xamarin.forms? 请更新我如何使用xamarin.forms从两个设备的库中选择多个图像?
Regards, Anand Dubey 此致,Anand Dubey
Firstly for select multiple images in Xamarin Forms, you should do a dependency service for each platform. 首先,对于在Xamarin Forms中选择多个图像,您应该为每个平台执行依赖服务。
In Android use: 在Android中使用:
.PutExtra (Intent.ExtraAllowMultiple, true);
Ex: 例如:
[assembly: Xamarin.Forms.Dependency (typeof (MediaService))]
namespace MyProject
{
public class MediaService : Java.Lang.Object, IMediaService
{
public MediaService ()
{
}
public void OpenGallery()
{
Toast.MakeText (Xamarin.Forms.Forms.Context, "Select max 20 images", ToastLength.Long).Show ();
var imageIntent = new Intent(
Intent.ActionPick);
imageIntent.SetType ("image/*");
imageIntent.PutExtra (Intent.ExtraAllowMultiple, true);
imageIntent.SetAction (Intent.ActionGetContent);
((Activity)Forms.Context).StartActivityForResult(
Intent.CreateChooser (imageIntent, "Select photo"), 0);
}
}
}
In IOS: 在IOS中:
Install this control: ELCImagePicker
And: 和:
[assembly: Xamarin.Forms.Dependency (typeof (MediaService))]
namespace MyProject
{
public class MediaService: IMediaService, IMessanger
{
public MediaService ()
{
}
public void OpenGallery()
{
var picker = ELCImagePickerViewController.Instance;
picker.MaximumImagesCount = 15;
picker.Completion.ContinueWith (t => {
picker.BeginInvokeOnMainThread(()=>
{
//dismiss the picker
picker.DismissViewController(true,null);
if (t.IsCanceled || t.Exception != null) {
} else {
Util.File.Path = new List<string>();
var items = t.Result as List<AssetResult>;
foreach (var item in items) {
Util.File.Path.Add (item.Path);
}
MessagingCenter.Send<IMessanger> (this, "PostProject");
}
});
});
var topController = UIApplication.SharedApplication.KeyWindow.RootViewController;
while (topController.PresentedViewController != null) {
topController = topController.PresentedViewController;
}
topController.PresentViewController (picker, true, null);
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.