Xamarin.Essentials 1.6 release notes

Getting Started | What's New | Breaking Changes | Blogs | Thank you | Feedback | Open Source

What's New in this Release

macOS Support

You can now install and use Xamarin.Essentials in macOS applications. Supported versions of macOS are macOS Sierra (10.12.6) and higher. See the platform support documentation to see what features are supported.

App Actions

Create and react to shortcuts from the applications icon.

try
{
    await AppActions.SetAsync(
        new AppAction("app_info", "App Info", icon: "app_info_action_icon"),
        new AppAction("battery_info", "Battery Info"));
}
catch (FeatureNotSupportedException ex)
{
    Debug.WriteLine("App Actions not supported");
}

Contacts

The Contacts class lets a user pick a contact and retrieve information about it.

try
{
    var contact = await Contacts.PickContactAsync();

    if(contact == null)
        return;

    var name = contact.Name;
    var contactType = contact.ContactType; // Unknown, Personal, Work
    var numbers = contact.Numbers; // List of phone numbers
    var emails = contact.Emails; // List of email addresses 
    
}
catch (Exception ex)
{
    // Handle exception here.
}

File Picker

The FilePicker API allows users to select a single or multiple files from the document browser. This includes generic documents or media content and this can be filtered down by PickOptions that are specified when calling any of the methods.

async Task<FileResult> PickAndShow(PickOptions options)
{
    try
    {
        var result = await FilePicker.PickAsync();
        if (result != null)
        {
            Text = $"File Name: {result.FileName}";
            if (result.FileName.EndsWith("jpg", StringComparison.OrdinalIgnoreCase) ||
                result.FileName.EndsWith("png", StringComparison.OrdinalIgnoreCase))
            {
                var stream = await result.OpenReadAsync();
                Image = ImageSource.FromStream(() => stream);
            }
        }
    }
    catch (Exception ex)
    {
        // The user canceled or something went wrong
    }
}

Haptic Feedback

The Haptic Feedback functionality can be performed with a Click or LongPress feedback type to vibrate the device.

try
{
    // Perform click feedback
    HapticFeedback.Perform(HapticFeedbackType.Click);

    // Or use long press    
    HapticFeedback.Perform(HapticFeedbackType.LongPress);
}
catch (FeatureNotSupportedException ex)
{
    // Feature not supported on device
}
catch (Exception ex)
{
    // Other error has occurred.
}

Media Picker

The MediaPicker allows the following operations.

  • PickPhotoAsync: Opens the media browser to select a photo.
  • CapturePhotoAsync: Opens the camera to take a photo.
  • PickVideoAsync: Opens the media browser to select a video.
  • CaptureVideoAsync: Opens the camera to take a video.
async Task TakePhotoAsync()
{
    try
    {
        var photo = await MediaPicker.CapturePhotoAsync();
        await LoadPhotoAsync(photo);
        Console.WriteLine($"CapturePhotoAsync COMPLETED: {PhotoPath}");
    }
    catch (Exception ex)
    {
        Console.WriteLine($"CapturePhotoAsync THREW: {ex.Message}");
    }
}

Screenshot

The Screenshot class lets take a capture of the current displayed screen of the app.

async Task CaptureScreenshot()
{
    var screenshot = await Screenshot.CaptureAsync();
    var stream = await screenshot.OpenReadAsync();

    Image = ImageSource.FromStream(() => stream);
}

Other Features

Release History

  • Friday, September 25, 2020 - Xamarin.Essentials 1.6.0-pre2
  • Tuesday, September 15, 2020 - Xamarin.Essentials 1.6.0-pre1

Xamarin.Essentials 1.6.0

Issues Fixed

  • GH-1358 Fix WebAuthenticator on UWP from throwing FileNotFoundException
  • GH-1354 Null checks on Android's file provider
  • GH-1296 Fix iOS leak on WebAuthenticator
  • GH-1319 Fix iOS speakback not stopping on cancel
  • And more

API Changes

  • None

Breaking Changes

  • None

Blogs

Xamarin Blogs

Thank you

Thank you to our community for helping to make Xamarin.Essentials even better!

This release, we received amazing contributions from these individuals:

Give them a big round of applause!

Feedback

Your feedback is important to us. If you encounter problems with Xamarin.Essentials, check the Xamarin Forums and Xamarin.Forms GitHub for existing issues. Report new issues and suggestions on GitHub.

Open Source

Xamarin.Essentials 1.6.0 is based on the open-source Xamarin.Essentials repository: