Awesome Open Source
Awesome Open Source



NuGet Badge NuGet downloads license Xamarin.MediaGallery on YouTube Video Views

This plugin is designed for picking and saving photos and video files from the native gallery of Android and iOS devices.

Unfortunately, at the time of the release of this plugin, MediaPlugin by @jamesmontemagno is no longer supported, and Xamarin.Essentials has not received updates for about 2 months. This plugin has fixed bugs and added some features that are missing in Xamarin.Essentials. I hope that in the future it will be ported to MAUI so that developers have an easy way to add these features to their apps.

Available Platforms

Platform Version Minimum OS Version
Android MonoAndroid 10.0+ 5.0
iOS Xamarin.iOS10 11.0
.NET Standard 2.0 -

Getting started

You can just watch the Video that @jfversluis published


In the Android project's MainLauncher or any Activity that is launched, this plugin must be initialized in the OnCreate method:

protected override void OnCreate(Bundle savedInstanceState)
    NativeMedia.Platform.Init(this, savedInstanceState);

iOS (Optional)

In the iOS project's AppDelegate that is launched, this plugin can be initialized in the FinishedLaunching method:

public override bool FinishedLaunching(UIApplication app, NSDictionary options)
    LoadApplication(new App());
    return base.FinishedLaunching(app, options);

public UIViewController GetTopViewController()
    var vc = UIApplication.SharedApplication.KeyWindow.RootViewController;

    if (vc is UINavigationController navController)
        vc = navController.ViewControllers.Last();

    return vc;


This method does not require requesting permissions from users

var cts = new CancellationTokenSource();
IMediaFile[] files = null;

    var request = new MediaPickRequest(1, MediaFileType.Image, MediaFileType.Video)
        PresentationSourceBounds = System.Drawing.Rectangle.Empty,
        UseCreateChooser = true,
        Title = "Select"


    var results = await MediaGallery.PickAsync(request, cts.Token);
    files = results?.Files?.ToArray();
catch (OperationCanceledException)
    // handling a cancellation request
catch (Exception)
    // handling other exceptions

if (files == null)

foreach (var file in files)
    var fileName = file.NameWithoutExtension; //Can return an null or empty value
    var extension = file.Extension;
    var contentType = file.ContentType;
    using var stream = await file.OpenReadAsync();

This method has two overloads:

  • Task<MediaPickResult> PickAsync(int selectionLimit = 1, params MediaFileType[] types)
  • Task<MediaPickResult> PickAsync(MediaPickRequest request, CancellationToken token = default)


To handle runtime results on Android, this plugin must receive any OnActivityResult.

protected override void OnActivityResult(int requestCode, Result resultCode, Intent intent)
   if (NativeMedia.Platform.CheckCanProcessResult(requestCode, resultCode, intent))
   NativeMedia.Platform.OnActivityResult(requestCode, resultCode, intent);
   base.OnActivityResult(requestCode, resultCode, intent);
  • When using the PickAsync method the selectionLimit parameter just sets multiple pick allowed
  • A request to cancel PickAsync method will cancel a task, but the picker UI can remain open until it is closed by the user
  • The use of Title property depends on each device
  • UseCreateChooser specifies whether to use Intent.CreateChooser


  • Multi picking is supported since iOS version 14.0+ On older versions, the plugin will prompt the user to select a single file
  • The NameWithoutExtension property on iOS versions before 14 returns a null value if the permission to access photos was not granted
  • Title property not used
  • UseCreateChooser property not used

Presentation Location

When picking files on iPadOS you have the ability to present in a pop over control. This specifies where the pop over will appear and point an arrow directly to. You can specify the location using the PresentationSourceBounds property. Setting this property has the same behavior as Launcher or Share in Xamarin.Essentials.



var status = await Permissions.RequestAsync<SaveMediaPermission>();

if (status != PermissionStatus.Granted)

await MediaGallery.SaveAsync(MediaFileType.Video, filePath);

//OR Using a byte array or a stream

await MediaGallery.SaveAsync(MediaFileType.Image, stream, fileName);

//The name or the path to the saved file must contain the extension.



Open the AndroidManifest.xml file under the Properties folder and add the following inside of the manifest node.

<!-- for saving photo/video -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  • When saving media files, the date and time are appended to the file name


In your Info.plist add the following keys:

<!-- for saving photo/video on iOS 14+ -->
<string>This app needs access to the photo gallery for saving photos and videos</string>

<!-- for saving photo/video on older versions -->
<string>This app needs access to the photo gallery for saving photos and videos</string>


______________ iOS Android ______________
iOS Android

Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
C Sharp (278,472
Android (41,017
Image (4,715
Video (4,426
Xamarin (1,773
Xamarin Forms (1,249
Media (859
Xamarin Android (469
Xamarin Ios (329
Related Projects