Esempio n. 1
0
        public static void Capture(Activity activity)
        {
            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);
            }

            if (cameraIntents.Count == 1)
            {
                activity.StartActivityForResult(cameraIntents[0], INTENT_PICK_IMAGE);
            }
            else
            {
                // Chooser of filesystem options.
                Intent chooserIntent = Intent.CreateChooser(cameraIntents[0], "Select Source");

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

                activity.StartActivityForResult(chooserIntent, INTENT_PICK_IMAGE);
            }
        }
Esempio n. 2
0
        private void SaveToGallery()
        {
            if (_picture != null && _picture.IsLoaded)
            {
                var fPath = DroidUtil.GetChadderTempFile();
                var image = File.Create(fPath);

                FileStream stream = image;

                Bitmap bmp = _picture.Image;
                bmp.Compress(Bitmap.CompressFormat.Jpeg, 100, stream);

                stream.Close();


                // Add file to Gallery
                Intent          mediaScanIntent = new Intent(Intent.ActionMediaScannerScanFile);
                Android.Net.Uri contentUri      = Android.Net.Uri.FromFile(new Java.IO.File(fPath));
                mediaScanIntent.SetData(contentUri);
                Activity.SendBroadcast(mediaScanIntent);

                DisplayToast("Image saved");
            }
            else
            {
                DisplayToast("Can\'t save this picture.");
            }
        }
Esempio n. 3
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);
            }
        }