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<string> _filesScheduledForDeletion
Field Value
- List<string>
_persistBetweenScenes
Should this object persist between scenes?
protected bool _persistBetweenScenes
Field Value
- bool
_pluginInstance
The native plugin instance.
protected AndroidJavaObject? _pluginInstance
Field Value
- AndroidJavaObject?
Properties
AndroidPathHelper
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()
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
fileName
stringThe name of the file.
basePath
stringThe path to the file. If not given, it will expect the file in a subdirectory named "ShareCache" under the app's cache directory.
fileProviderAuthority
stringThe 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
focus
bool
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
contentType
stringThe MIME type of the content to share. See CommonMimeTypes for common MIME types.
fileName
stringThe file name of the content to share (eg. "image.png").
data
byte[]The data to share.
additionalData
AdditionalShareDataAdditional data for the event.
Returns
- bool
True if successful, false otherwise.
Remarks
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
contentType
stringThe 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.
additionalData
AdditionalShareDataAdditional data for the event.
Returns
- bool
True if successful, false otherwise.
Remarks
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
contentType
stringThe MIME type of the content to share. See CommonMimeTypes for common MIME types.
fileName
stringThe name of the file to share.
additionalData
AdditionalShareDataAdditional 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
contentType
stringThe MIME type of the content to share. See CommonMimeTypes for common MIME types.
fileNames
string[]The names of the files to share.
additionalData
AdditionalShareDataAdditional 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.
ShareText(string, string?)
Shares text to other apps using the system share sheet.
public void ShareText(string text, string? title = null)
Parameters
text
stringThe text to share.
title
stringOptional title for the share sheet (Android 10+).
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
contentType
stringThe MIME type of the content to share. See CommonMimeTypes for common MIME types.
uris
AndroidJavaObject[]The native file URI objects to share.
textContent
stringAdditional text to be shared along with the main content.
title
stringOptional title for the share sheet (Android 10+, but not guaranteed to work when sharing non-text media).