/// <summary>
        /// Called when an activity you launched exits, giving you the requestCode you started it with, the
        /// resultCode it returned, and any additional data from it.
        /// </summary>
        /// <param name="requestCode">
        ///   The integer request code originally supplied to startActivityForResult(), allowing you to identify who
        ///   this result came from.
        /// </param>
        /// <param name="resultCode">
        ///   The integer result code returned by the child activity through its setResult().
        /// </param>
        /// <param name="data">
        ///   An Intent, which can return result data to the caller (various data can be attached to Intent "extras").
        /// </param>
        protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
        {
            base.OnActivityResult(requestCode, resultCode, data);

            // If the operation was tasked
            if (this.tasked)
            {
                // Get the media from task result
                var future = resultCode == Result.Canceled
                                 ? MediaPickerActivity.TaskFromResult(new MediaPickedEventArgs(requestCode, true))
                                 : MediaPickerActivity.GetMediaFileAsync(
                    this,
                    requestCode,
                    this.action,
                    this.isPhoto,
                    ref this.path,
                    data?.Data);

                // Finish the current activity
                this.Finish();
                future.ContinueWith(t => MediaPickerActivity.RaiseOnMediaPicked(t.Result));
            }
            else
            {
                // If the task was canceled
                if (resultCode == Result.Canceled)
                {
                    this.SetResult(Result.Canceled);
                }
                else
                {
                    // Return the media resule
                    var resultData = new Intent();
                    resultData.PutExtra(MediaPickerActivity.MediaFileExtraName, data?.Data);
                    resultData.PutExtra(MediaPickerActivity.ExtraPath, this.path);
                    resultData.PutExtra("isPhoto", this.isPhoto);
                    resultData.PutExtra(MediaPickerActivity.ExtraAction, this.action);

                    this.SetResult(Result.Ok, resultData);
                }

                // Finish the current activity
                this.Finish();
            }
        }
        /// <summary>
        /// Called when the activity is starting.
        /// </summary>
        /// <param name="savedInstanceState">
        ///   If the activity is being re-initialized after previously being shut down then this Bundle contains
        ///   the data it most recently supplied in <see cref="OnSaveInstanceState"/>. Otherwise it is <c>null</c>.
        /// </param>
        protected override void OnCreate(Bundle savedInstanceState)
        {
            // Call the base member
            base.OnCreate(savedInstanceState);

            // Take the state from the saved instance or an intent
            var b   = savedInstanceState ?? this.Intent.Extras;
            var ran = b.GetBoolean("ran", false);

            this.title       = b.GetString(MediaStore.MediaColumns.Title);
            this.description = b.GetString(MediaStore.Images.ImageColumns.Description);
            this.tasked      = b.GetBoolean(MediaPickerActivity.ExtraTasked);
            this.id          = b.GetInt(MediaPickerActivity.ExtraId, 0);
            this.type        = b.GetString(MediaPickerActivity.ExtraType);

            // Parse media type
            if (this.type == "image/*")
            {
                this.isPhoto = true;
            }

            // Get the requested action
            this.action = b.GetString(MediaPickerActivity.ExtraAction);
            Intent pickIntent = null;

            try
            {
                // Create the media pick intent
                pickIntent = new Intent(this.action);
                if (this.action == Intent.ActionPick)
                {
                    pickIntent.SetType(this.type);
                }
                else
                {
                    // Setup the video properties for video
                    pickIntent.PutExtra(MediaStore.ExtraVideoQuality, 1);
                    if (!this.isPhoto)
                    {
                        this.durationLimit = b.GetInt(MediaStore.ExtraDurationLimit, 0);
                        if (this.durationLimit != 0)
                        {
                            pickIntent.PutExtra(MediaStore.ExtraDurationLimit, this.durationLimit);
                        }
                    }

                    // If the activity was not run
                    if (!ran)
                    {
                        this.path = MediaPickerActivity.GetOutputMediaFile(
                            this,
                            b.GetString(MediaPickerActivity.ExtraPath),
                            this.title,
                            this.isPhoto);
                        this.Touch();
                        pickIntent.PutExtra(MediaStore.ExtraOutput, this.path);
                    }
                    else
                    {
                        // Get the media location
                        this.path = Uri.Parse(b.GetString(MediaPickerActivity.ExtraPath));
                    }
                }

                // If the activity was not run before for the current operation
                if (!ran)
                {
                    // Check camera permission
                    if (global::Android.OS.Build.VERSION.Release == "6.0")
                    {
                        if (this.CheckSelfPermission(Manifest.Permission.Camera)
                            != Android.Content.PM.Permission.Granted)
                        {
                            this.RequestPermissions(new[] { Manifest.Permission.Camera }, 1);
                        }
                    }

                    // Start the media operation
                    this.StartActivityForResult(pickIntent, this.id);
                }
            }
            catch (Exception ex)
            {
                // Handle exception
                MediaPickerActivity.RaiseOnMediaPicked(new MediaPickedEventArgs(this.id, ex));
            }
            finally
            {
                // Cleanup
                pickIntent?.Dispose();
            }
        }