예제 #1
0
        public static void PickFromGallery(Activity activity = null, FragmentCompat fragment = null)
        {
            // Filesystem.
            Intent galleryIntent = new Intent();

            galleryIntent.SetType("image/*");
            galleryIntent.SetAction(Intent.ActionGetContent);

            // Chooser of filesystem options.
            Intent chooserIntent = Intent.CreateChooser(galleryIntent, "Select Source");

            if (activity != null)
            {
                activity.StartActivityForResult(chooserIntent, INTENT_PICK_IMAGE);
            }
            if (fragment != null)
            {
                fragment.StartActivityForResult(chooserIntent, INTENT_PICK_IMAGE);
            }
        }
예제 #2
0
        private static void MultiSourceDialog(Activity activity, FragmentCompat fragment = null)
        {
            List <Intent>       cameraIntents  = new List <Intent>();
            Intent              captureIntent  = new Intent(MediaStore.ActionImageCapture);
            PackageManager      packageManager = activity.PackageManager;
            IList <ResolveInfo> listCam        = packageManager.QueryIntentActivities(captureIntent, 0);

            foreach (ResolveInfo res in listCam)
            {
                String packageName = res.ActivityInfo.PackageName;
                Intent intent      = new Intent(captureIntent);
                intent.SetComponent(new ComponentName(res.ActivityInfo.PackageName, res.ActivityInfo.Name));
                intent.SetPackage(packageName);
                TempFile = DroidUtil.GetChadderTempFile();
                intent.PutExtra(MediaStore.ExtraOutput, Android.Net.Uri.FromFile(new Java.IO.File(TempFile)));
                cameraIntents.Add(intent);
            }

            // Filesystem.
            Intent galleryIntent = new Intent();

            galleryIntent.SetType("image/*");
            galleryIntent.SetAction(Intent.ActionGetContent);

            // Chooser of filesystem options.
            Intent chooserIntent = Intent.CreateChooser(galleryIntent, "Select Source");

            // Add the camera options.
            chooserIntent.PutExtra(Intent.ExtraInitialIntents, cameraIntents.ToArray <IParcelable>());

            if (fragment == null)
            {
                activity.StartActivityForResult(chooserIntent, INTENT_PICK_IMAGE);
            }
            else
            {
                fragment.StartActivityForResult(chooserIntent, INTENT_PICK_IMAGE);
            }
        }