Class ShareSheetManager
Class to handle the share sheet functionality.
public class ShareSheetManager : Singleton<ShareSheetManager>
- Inheritance
-
objectShareSheetManager
Fields
AndroidFileProviderAuthority
The Android FileProvider URI authority the application has set in its manifest to use for share actions. If not provided, defaults to "{Application.identifier}.FileProvider".
public string AndroidFileProviderAuthority
Field Value
- string
AndroidNativeClass
The fully qualified name of the native Android plugin class.
protected const string AndroidNativeClass = "com.uralstech.ushare.ShareHelper"
Field Value
- string
DefaultFileProviderAuthorityFormat
Default format for the Android FileProvider URI authority.
protected const string DefaultFileProviderAuthorityFormat = "{0}.FileProvider"
Field Value
- string
DefaultSaveSubDirectory
The default directory used to temporarily save data that is shared.
protected const string DefaultSaveSubDirectory = "ShareCache"
Field Value
- string
_filesScheduledForDeletion
List of files scheduled for deletion after a share action has been completed.
protected readonly List<(long, string)> _filesScheduledForDeletion
Field Value
- List<(long, string)>
_persistBetweenScenes
Should this object persist between scenes?
protected bool _persistBetweenScenes
Field Value
- bool
_pluginInstance
(Android) The native plugin instance.
protected AndroidJavaObject? _pluginInstance
Field Value
- AndroidJavaObject?
Properties
AndroidPathHelper
(Android) Utility object for Android which provides paths to where shareable data can be saved.
public AndroidPathHelper AndroidPathHelper { get; protected set; }
Property Value
Methods
Awake()
protected void Awake()
DeleteScheduledFiles(long, bool)
Deletes files from _filesScheduledForDeletion that match the given timestamp,
unless overriden using deleteAll.
protected void DeleteScheduledFiles(long timestamp, bool deleteAll = false)
Parameters
timestamplongThe timestamp to match for in _filesScheduledForDeletion.
deleteAllboolSet this to true to override the timestamp check.
GetDefaultBasePath()
Gets the default shareable directory as defined in the native plugin.
public string GetDefaultBasePath()
Returns
- string
GetShareableFileUri(string, string?, string?)
(Android) Gets a shareable URI for a file located in a shareable directory in the app's storage.
public AndroidJavaObject? GetShareableFileUri(string fileName, string? basePath = null, string? fileProviderAuthority = null)
Parameters
fileNamestringThe name of the file.
basePathstringThe path to the file. If not given, it will expect the file in a subdirectory named "ShareCache" under the app's cache directory.
fileProviderAuthoritystringThe FileProvider authority for the file being shared.
Returns
- AndroidJavaObject?
The native Android URI object or null if it could not create the URI.
OnApplicationFocus(bool)
protected void OnApplicationFocus(bool focus)
Parameters
focusbool
OnDestroy()
protected void OnDestroy()
ShareData(string, string, byte[], AdditionalShareData)
Shares data as a file URI to other apps using the system share sheet.
public bool ShareData(string contentType, string fileName, byte[] data, AdditionalShareData additionalData = default)
Parameters
contentTypestringThe MIME type of the content to share. See CommonMimeTypes for common MIME types.
fileNamestringThe file name of the content to share (eg. "image.png").
databyte[]The data to share.
additionalDataAdditionalShareDataAdditional data for the event.
Returns
- bool
True if successful, false otherwise.
Remarks
On iOS, for images, the data is marshalled directly into the native code without any IO operations.
This method writes the data to a file in a folder that is accessible by other apps, and then shares its location as a URI. By default, this location is in the app's cache directory under a subdirectory named "ShareCache". When the user regains focus on the app after sharing, the file will be deleted to prevent the cache directory from growing too large. These settings can be overridden by setting the AdditionalShareData parameter.
ShareData(string, (string FileName, byte[] Data)[], AdditionalShareData)
Shares data as multiple file URIs to other apps using the system share sheet.
public bool ShareData(string contentType, (string FileName, byte[] Data)[] files, AdditionalShareData additionalData = default)
Parameters
contentTypestringThe MIME type of the content to share. See CommonMimeTypes for common MIME types.
files(string FileName, byte[] Data)[]An array of tuples containing file names and their corresponding data to share.
additionalDataAdditionalShareDataAdditional data for the event.
Returns
- bool
True if successful, false otherwise.
Remarks
On iOS, for image-only requests, the data is marshalled directly into the native code without any IO operations.
This method writes the data to files in a folder that is accessible by other apps, and then shares its location as a URI. By default, this location is in the app's cache directory under a subdirectory named "ShareCache". When the user regains focus on the app after sharing, the file will be deleted to prevent the cache directory from growing too large. These settings can be overridden by setting the AdditionalShareData parameter.
ShareFile(string, string, AdditionalShareData)
Shares a file as a URI to other apps using the system share sheet.
public bool ShareFile(string contentType, string fileName, AdditionalShareData additionalData = default)
Parameters
contentTypestringThe MIME type of the content to share. See CommonMimeTypes for common MIME types.
fileNamestringThe name of the file to share.
additionalDataAdditionalShareDataAdditional data for the event.
Returns
- bool
True if successful, false otherwise.
Remarks
By default, the file is expected to be in the app's cache directory under a subdirectory named "ShareCache". This can be overridden by setting the AdditionalShareData parameter.
ShareFileCallback(long)
Default implementation of IOSNativeCalls.ShareFileCallback.
protected static void ShareFileCallback(long timestamp)
Parameters
timestamplongThe timestamp of the original request.
ShareFileImpl(long, string, string, AdditionalShareData)
Shares a file as a URI to other apps using the system share sheet.
protected bool ShareFileImpl(long timestamp, string contentType, string fileName, AdditionalShareData additionalData)
Parameters
timestamplongTimestamp to be passed into the native iOS plugin.
contentTypestringThe MIME type of the content to share. See CommonMimeTypes for common MIME types.
fileNamestringThe name of the file to share.
additionalDataAdditionalShareDataAdditional data for the event.
Returns
- bool
True if successful, false otherwise.
Remarks
By default, the file is expected to be in the app's cache directory under a subdirectory named "ShareCache". This can be overridden by setting the AdditionalShareData parameter.
ShareFiles(string, string[], AdditionalShareData)
Shares multiple files as URIs to other apps using the system share sheet.
public bool ShareFiles(string contentType, string[] fileNames, AdditionalShareData additionalData = default)
Parameters
contentTypestringThe MIME type of the content to share. See CommonMimeTypes for common MIME types.
fileNamesstring[]The names of the files to share.
additionalDataAdditionalShareDataAdditional data for the event.
Returns
- bool
True if successful, false otherwise.
Remarks
By default, the files are expected to be in the app's cache directory under a subdirectory named "ShareCache". This can be overridden by setting the AdditionalShareData parameter.
If you want to share files that are present in different directories, you will have to get the shareable URIs for those files individually using (Android) GetShareableFileUri(string, string?, string?) and then share them using (Android) ShareUris(string, AndroidJavaObject[], string?, string?) method.
ShareFilesImpl(long, string, string[], AdditionalShareData)
Shares multiple files as URIs to other apps using the system share sheet.
protected bool ShareFilesImpl(long timestamp, string contentType, string[] fileNames, AdditionalShareData additionalData)
Parameters
timestamplongTimestamp to be passed into the native iOS plugin.
contentTypestringThe MIME type of the content to share. See CommonMimeTypes for common MIME types.
fileNamesstring[]The names of the files to share.
additionalDataAdditionalShareDataAdditional data for the event.
Returns
- bool
True if successful, false otherwise.
Remarks
By default, the files are expected to be in the app's cache directory under a subdirectory named "ShareCache". This can be overridden by setting the AdditionalShareData parameter.
If you want to share files that are present in different directories, you will have to get the shareable URIs for those files individually using (Android) GetShareableFileUri(string, string?, string?) and then share them using (Android) ShareUris(string, AndroidJavaObject[], string?, string?) method.
ShareImageImpl(byte[], AdditionalShareData)
(iOS) Shares an image to other apps using the system share sheet.
protected bool ShareImageImpl(byte[] data, AdditionalShareData additionalData)
Parameters
databyte[]The image to share.
additionalDataAdditionalShareDataAdditional data for the event.
Returns
- bool
True if successful, false otherwise.
ShareImagesImpl((string, byte[] Data)[], AdditionalShareData)
(iOS) Shares images to other apps using the system share sheet.
protected bool ShareImagesImpl((string, byte[] Data)[] files, AdditionalShareData additionalData)
Parameters
files(string FileName, byte[] Data)[]An array of tuples containing file names (ignored) and their corresponding data to share.
additionalDataAdditionalShareDataAdditional data for the event.
Returns
- bool
True if successful, false otherwise.
ShareText(string, string?)
Shares text to other apps using the system share sheet.
public bool ShareText(string text, string? title = null)
Parameters
textstringThe text to share.
titlestringOptional title for the share sheet (Android 10+).
Returns
- bool
If the share request was executed successfully.
ShareUris(string, AndroidJavaObject[], string?, string?)
(Android) Shares URIs, which point to files, to other apps using the system share sheet.
public void ShareUris(string contentType, AndroidJavaObject[] uris, string? textContent = null, string? title = null)
Parameters
contentTypestringThe MIME type of the content to share. See CommonMimeTypes for common MIME types.
urisAndroidJavaObject[]The native file URI objects to share.
textContentstringAdditional text to be shared along with the main content.
titlestringOptional title for the share sheet (Android 10+, but not guaranteed to work when sharing non-text media).