MAUI Storage

This service is used to provide MAUI Essentials functionality to those using the trellispark MAUI application. Specifically the IFilePicker, IMediaPicker, and IBrowser interfaces are used which allow the ability to open and use the devices file picker to select a file, open and use the devices camera to take a picture or record a video, or open the devices default browser to a specific URL to download a file to the device when using the MAUI application.

This service is registered as a singleton service in the website and hybrid projects.

All methods in this service will return a string or an object that contains an ErrorMessage property. If the returned string or ErrorMessage property is empty, then the operation was successful. Otherwise, there was an issue, and the error is logged. The returned string or ErrorMessage property can be displayed in an error notification to give the user visual feedback that something went wrong.

This service implements the IGI_Storage interface and it’s reference name is DeviceStorage. Key properties and methods this service provides are the following:

  • bool IsAvailable – The value True is returned since the user is using the trellispark MAUI application.
  • Task<StorageInformation> OpenFilePicker() – When called this method will open the devices file explorer so the user can select a file.
  • Task<string> DownloadFileFromURL(string url) – When called this method will open the devices default web browser and navigate to the URL of the file to download.
  • Task<StorageInformation> CapturePhoto() – When called this method will open the devices camera to take a photo.
  • Task<StorageInformation> CaptureVideo() – When called this method will open the devices camera and microphone to record a video.

The images below are a visual example of what the methods above do

IMPORTANT NOTE (Android Only): To interact with the camera the device needs to allow write permissions, in API 33 the permissions have changed and Microsoft updated MAUI so it’s suggested to use target SDK version 32 in your Android manifest file instead of 33.

Updated on January 30, 2023

Was this article helpful?

Related Articles

Need Support?
Can’t find the answer you’re looking for? Don’t worry we’re here to help!
Contact Support

Leave a Comment