Essential Kit Tutorials
DocumentationDownload
Latest(v3)
Latest(v3)
  • Introduction
  • Features Overview
  • Whats new in v3
    • Version 3 vs Version 2
    • Release Notes
    • Upgrade from V2
  • Plugin Overview
    • Settings
    • Folder Structure
    • Installation FAQ
    • Upgrade Guide
  • Features
    • 📒Address Book
      • Setup
      • Usage
      • Testing
      • FAQ
    • App Shortcuts
      • Setup
      • Usage
    • 🆕App Updater
      • Setup
      • Usage
      • Testing
    • 💲Billing Services
      • Setup
        • iOS
        • Android
      • Usage
      • Testing
        • iOS
        • Android
      • FAQ
    • ☁️Cloud Services
      • Setup
        • iOS
        • Android
      • Usage
      • Testing
      • FAQ
    • 🔗Deep Link Services
      • Setup
        • iOS
        • Android
      • Usage
      • Testing
      • FAQ
    • 🛠️Utilities (Extras)
      • Usage
    • 💯Game Services
      • Setup
        • iOS
        • Android
      • Usage
      • FAQ
    • 📸Media Services
      • Setup
      • Usage
      • FAQ
    • 📆Native UI
      • Setup
      • Usage
      • FAQ
      • Examples
        • Login Dialog
    • Network Services
      • Setup
      • Usage
      • FAQ
    • ⏰Notification Services
      • Setup
        • iOS
        • Android
      • Usage
      • Examples
        • Nudge to come-back to the game
      • FAQ
    • ⭐Rate My App
      • Setup
      • Usage
      • FAQ
    • 🤝Sharing
      • Setup
      • Usage
        • Message Composer
        • Mail Composer
        • Social Share Composer
        • Share Sheet
      • FAQ
      • Examples
        • Add Attachment Example
    • Task Services
      • Setup
      • Usage
    • 🌏Web View
      • Setup
      • Usage
      • FAQ
      • Examples
        • Loading Pdf File
  • Notes
    • Resolving Android Gradle Build Errors
    • Google Play Services Authentication
    • Target API Level vs Min API Level
    • Handling Refunds for In-App Purchases (Billing Services)
Powered by GitBook
On this page

Was this helpful?

Edit on GitHub
  1. Features
  2. Sharing
  3. Examples

Add Attachment Example

Example to add a zip file as an attachment

public void ShareAttachment(string title, string path, string mimeType, string filename)
{
    ShareSheet shareSheet = ShareSheet.CreateInstance();
    shareSheet.AddText(title);
    StartCoroutine(GetFileAsByteArray(path, (data) =>
    {
        shareSheet.AddAttachment(data, mimeType, filename);
        shareSheet.Show();
        
    }));
}

#region Helpers
private IEnumerator GetFileAsByteArray(string filePath, Action<byte[]> callback)
{
    var sanitizedFilePath = GetSanitizedFilePath(filePath);
    UnityWebRequest request = UnityWebRequest.Get(sanitizedFilePath);
    yield return request.SendWebRequest();

    Debug.LogError("File path : " + sanitizedFilePath);
    if (request.isNetworkError || request.isHttpError)
    {
        Debug.LogError(request.error);
        callback?.Invoke(null);
    }
    else
    {
        callback?.Invoke(request.downloadHandler.data);
    }
}

private string GetSanitizedFilePath(string filePath)
{
    if (filePath == null)
        return null;

    if (filePath.StartsWith("jar:") || filePath.StartsWith("file:"))
        return filePath;

    return Path.Combine("file://", filePath);
}
#endregion

Usage

ShareAttachment("Sharing a zip file", Path.Combine(Application.streamingAssetsPath, "test.zip"), "application/zip", "test");

Note that the sharing content may or may not be compatible with the sharing service. Handling of the content is totally controlled by the service being used to share. Essential Kit only provides a way to share the content to the services and actual sharing is handled by the sharing service being used.

PreviousExamplesNextTask Services

Last updated 2 months ago

Was this helpful?

🤝