How can i limit quantity of elements to select from gallery?

CharlinCharlin DOUniversity ✭✭
edited May 2015 in Xamarin.Forms

Hello,
I want to limit the quantity of element that a user can select from gallery:

This is my actual code:

public void OpenGallery()
{
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);
}


protected override void OnActivityResult (int requestCode, Result resultCode, Intent intent)
{
base.OnActivityResult (requestCode, resultCode, intent);
string path = "";
if (resultCode == Result.Ok) {
paths = new List ();
if (intent != null) {
ClipData clipData = intent.ClipData;
if (clipData != null) {
for (int i = 0; i < clipData.ItemCount; i++) {
ClipData.Item item = clipData.GetItemAt (i);
global::Android.Net.Uri uri = item.Uri;

                        //In case you need image's absolute path
                        path = GetPathToImage (uri);
                        paths.Add (path);
                    }

                } else {
                    global::Android.Net.Uri uri = intent.Data;
                    path = GetPathToImage(uri);
                    paths.Add (path);
                }
                MessagingCenter.Send<IGestureListener, List<string>> (this, "ImagesPath", paths);
            }
            //Send the paths to forms

        }

    }

Best Answer

Answers

Sign In or Register to comment.