### Check if App is Installed (Android) Source: https://context7.com/yasirkula/unitynativeshare/llms.txt A static utility method that returns true if the specified Android app is installed. It checks by package name or package and activity class name. This method always returns true in the Unity Editor and on iOS. ```csharp // Check for WhatsApp before targeting it if (NativeShare.TargetExists("com.whatsapp")) { new NativeShare().AddFile(filePath).AddTarget("com.whatsapp").Share(); } // Check for a specific activity class bool twitterDMExists = NativeShare.TargetExists( "com.twitter.android", "com.twitter.android.DMActivity" ); Debug.Log($ ``` ```csharp Twitter DM activity exists: {twitterDMExists} ``` -------------------------------- ### Find App by Regex (Android) Source: https://context7.com/yasirkula/unitynativeshare/llms.txt A static utility that searches installed Android apps using regular expressions to find a matching package and activity class name. Returns true on a successful match. This method always returns false on iOS and in the Unity Editor. ```csharp string packageName, className; if (NativeShare.FindTarget(out packageName, out className, "com\.whatsapp.*\.*")) { Debug.Log($"Found: {packageName} / {className}"); new NativeShare() .AddFile(screenshotPath) .AddTarget(packageName, className) .Share(); } else { Debug.Log("No matching app found."); } ``` -------------------------------- ### NativeShare.TargetExists Source: https://context7.com/yasirkula/unitynativeshare/llms.txt A static utility method that returns true if the specified Android app (by package name, or package + activity class) is installed on the device. It always returns true in the Unity Editor and on iOS. ```APIDOC ## `NativeShare.TargetExists(string androidPackageName, string androidClassName = null)` ### Description Static utility that returns `true` if the specified Android app (by package name, or package + activity class) is installed on the device. Always returns `true` in the Unity Editor and on iOS. ### Method Signature `NativeShare.TargetExists(string androidPackageName, string androidClassName = null)` ### Parameters #### Path Parameters - **androidPackageName** (string) - Required - The package name of the Android app. - **androidClassName** (string) - Optional - The class name of the Android activity. ### Return Value (bool) - `true` if the app is installed, `false` otherwise. ### Example ```csharp // Check for WhatsApp before targeting it if (NativeShare.TargetExists("com.whatsapp")) { new NativeShare().AddFile(filePath).AddTarget("com.whatsapp").Share(); } // Check for a specific activity class bool twitterDMExists = NativeShare.TargetExists( "com.twitter.android", "com.twitter.android.DMActivity" ); Debug.Log($"Twitter DM activity exists: {twitterDMExists}"); ``` ``` -------------------------------- ### NativeShare.FindTarget Source: https://context7.com/yasirkula/unitynativeshare/llms.txt A static utility method that searches installed Android apps using regular expressions to find a matching package and activity class name. It returns true on a successful match and always returns false on iOS and in the Editor. ```APIDOC ## `NativeShare.FindTarget(out string packageName, out string className, string packageNameRegex, string classNameRegex = null)` ### Description Static utility that searches installed Android apps using regular expressions to find a matching package and activity class name. Returns `true` on a successful match. Always returns `false` on iOS and in the Editor. ### Method Signature `NativeShare.FindTarget(out string packageName, out string className, string packageNameRegex, string classNameRegex = null)` ### Parameters #### Path Parameters - **packageName** (out string) - Output - The package name of the found app. - **className** (out string) - Output - The class name of the found app. - **packageNameRegex** (string) - Required - The regular expression to match the package name. - **classNameRegex** (string) - Optional - The regular expression to match the class name. ### Return Value (bool) - `true` if a matching app is found, `false` otherwise. ### Example ```csharp string packageName, className; if (NativeShare.FindTarget(out packageName, out className, "com\.whatsapp.*", "com\.whatsapp\.ShareMediaActivity")) { Debug.Log($"Found: {packageName} / {className}"); new NativeShare() .AddFile(screenshotPath) .AddTarget(packageName, className) .Share(); } else { Debug.Log("No matching app found."); } ``` ``` -------------------------------- ### Share to a Specific App (Android) Source: https://context7.com/yasirkula/unitynativeshare/llms.txt Restrict the Android share sheet to a specific application by its package name. This method has no effect on iOS. Ensure the target application is installed before attempting to share. ```csharp if (NativeShare.TargetExists("com.whatsapp")) { new NativeShare() .AddFile(screenshotPath) .AddTarget("com.whatsapp") .Share(); } else { Debug.Log("WhatsApp is not installed."); } ``` -------------------------------- ### Add File by Path with MIME Type Source: https://context7.com/yasirkula/unitynativeshare/llms.txt Use AddFile to include local files in the share. The MIME type is auto-detected if not specified. Multiple files can be added. An error is logged if a specified file does not exist. ```csharp string screenshotPath = Path.Combine(Application.temporaryCachePath, "screenshot.png"); File.WriteAllBytes(screenshotPath, texture.EncodeToPNG()); new NativeShare() .AddFile(screenshotPath) // MIME auto-detected as image/png .AddFile("/path/to/video.mp4", "video/mp4") // explicit MIME .SetText("Check these out!") .Share(); ``` -------------------------------- ### Configure AndroidManifest.xml for Native Share Source: https://github.com/yasirkula/unitynativeshare/wiki/Manual-Setup-for-Android Add this XML snippet to your AndroidManifest.xml file within the tag. Ensure MY_UNIQUE_AUTHORITY is replaced with a unique string to avoid conflicts. ```xml ``` -------------------------------- ### Trigger Native Share Sheet Source: https://context7.com/yasirkula/unitynativeshare/llms.txt Presents the platform's native share UI with configured content. This method must be called after all configuration methods like SetText, AddFile, etc. It logs a warning and does nothing if no content has been set. ```csharp new NativeShare() .SetText("Check this out!") .SetUrl("https://example.com") .Share(); // opens the native share sheet immediately ``` -------------------------------- ### Add Texture2D Directly Source: https://context7.com/yasirkula/unitynativeshare/llms.txt Use AddFile with a Texture2D to save and share it. The format (PNG or JPEG) is determined by the filename extension. Non-readable textures are handled automatically. ```csharp // Share a screenshot captured this frame IEnumerator TakeScreenshotAndShare() { yield return new WaitForEndOfFrame(); Texture2D screenshot = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false); screenshot.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0); screenshot.Apply(); new NativeShare() .AddFile(screenshot, "screenshot.jpg") // saved as JPEG .SetSubject("My Score") .SetText("I just hit a new high score!") .SetCallback((result, target) => { Debug.Log($"Share result: {result}, app chosen: {target}"); }) .Share(); Destroy(screenshot); // avoid memory leak } ``` -------------------------------- ### NativeShare.AddFile (filePath) Source: https://context7.com/yasirkula/unitynativeshare/llms.txt Adds a file from the local filesystem to the share action. The MIME type is auto-detected from the file extension if not provided. Multiple files can be added. Logs an error if the file does not exist. ```APIDOC ## NativeShare.AddFile(string filePath, string mime = null) ### Description Adds a file from the local filesystem to the share action. The MIME type is auto-detected from the file extension if not provided. Multiple files can be added. Logs an error if the file does not exist. ### Method ```csharp string screenshotPath = Path.Combine(Application.temporaryCachePath, "screenshot.png"); File.WriteAllBytes(screenshotPath, texture.EncodeToPNG()); new NativeShare() .AddFile(screenshotPath) // MIME auto-detected as image/png .AddFile("/path/to/video.mp4", "video/mp4") // explicit MIME .SetText("Check these out!") .Share(); ``` ``` -------------------------------- ### NativeShare.AddFile (Texture2D) Source: https://context7.com/yasirkula/unitynativeshare/llms.txt Saves the given Texture2D to Application.temporaryCachePath as PNG or JPEG (determined by the filename extension) and adds it to the share action. Handles non-readable textures automatically using a RenderTexture copy. ```APIDOC ## NativeShare.AddFile(Texture2D texture, string createdFileName = "Image.png") ### Description Saves the given `Texture2D` to `Application.temporaryCachePath` as PNG or JPEG (determined by the filename extension) and adds it to the share action. Handles non-readable textures automatically using a `RenderTexture` copy. ### Method ```csharp // Share a screenshot captured this frame IEnumerator TakeScreenshotAndShare() { yield return new WaitForEndOfFrame(); Texture2D screenshot = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false); screenshot.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0); screenshot.Apply(); new NativeShare() .AddFile(screenshot, "screenshot.jpg") // saved as JPEG .SetSubject("My Score") .SetText("I just hit a new high score!") .SetCallback((result, target) => { Debug.Log($"Share result: {result}, app chosen: {target}"); }) .Share(); Destroy(screenshot); // avoid memory leak } ``` ``` -------------------------------- ### Handle Share Result Callback Source: https://context7.com/yasirkula/unitynativeshare/llms.txt Register a callback to be invoked after the share sheet is dismissed. The callback receives the share result and the target app, allowing for post-share actions or logging. Use this to track successful shares or user cancellations. ```csharp new NativeShare() .SetText("Hello World!") .SetCallback((ShareResult result, string shareTarget) => { switch (result) { case ShareResult.Shared: Debug.Log($"Shared successfully via: {shareTarget ?? "unknown"}"); // Check if user picked Twitter if (shareTarget != null && shareTarget.ToLowerInvariant().Contains("twitter")) Debug.Log("Shared to Twitter!"); break; case ShareResult.NotShared: Debug.Log("User cancelled sharing."); break; default: Debug.Log("Share result unknown."); break; } }) .Share(); ``` -------------------------------- ### Set Shared URL Source: https://context7.com/yasirkula/unitynativeshare/llms.txt Use SetUrl to include a web link with the share. On iOS, this can generate a preview. On Android, or when sharing files, the URL is appended to the text content. ```csharp new NativeShare() .SetText("Check out this game!") .SetUrl("https://example.com/mygame") .Share(); ``` -------------------------------- ### NativeShare.Share Source: https://context7.com/yasirkula/unitynativeshare/llms.txt Triggers the native share sheet, presenting the platform's native share UI with all previously configured content. This method must be called after all configuration methods. ```APIDOC ## `NativeShare.Share()` ### Description Presents the platform's native share UI with all previously configured content. Must be called after all configuration methods. Logs a warning and does nothing if no content has been set. ### Method Signature `NativeShare.Share()` ### Example ```csharp new NativeShare() .SetText("Check this out!") .SetUrl("https://example.com") .Share(); // opens the native share sheet immediately ``` ``` -------------------------------- ### Set Share Subject and Text Source: https://context7.com/yasirkula/unitynativeshare/llms.txt Use SetSubject to define the subject line, primarily for email clients. SetText defines the main body of the shared content. Both methods return the NativeShare instance for method chaining. ```csharp new NativeShare() .SetSubject("Check out this screenshot!") .SetText("Here is the screenshot I took.") .Share(); ``` -------------------------------- ### NativeShare.SetUrl Source: https://context7.com/yasirkula/unitynativeshare/llms.txt Sets a URL to include with the share. On iOS, supported apps use this to generate a webpage preview. On Android (or when a file is also attached on iOS), the URL is appended to the text. ```APIDOC ## NativeShare.SetUrl(string url) ### Description Sets a URL to include with the share. On iOS, supported apps use this to generate a webpage preview. On Android (or when a file is also attached on iOS), the URL is appended to the text. ### Method ```csharp new NativeShare() .SetText("Check out this game!") .SetUrl("https://example.com/mygame") .Share(); ``` ``` -------------------------------- ### NativeShare.SetCallback Source: https://context7.com/yasirkula/unitynativeshare/llms.txt Registers a callback that is invoked after the share sheet is dismissed. The callback receives a ShareResult enum value and the package/class name of the app the user selected. ```APIDOC ## `NativeShare.SetCallback(ShareResultCallback callback)` ### Description Registers a callback invoked after the share sheet is dismissed. The callback receives a `ShareResult` enum value and the package/class name of the app the user selected (may be null). `ShareResult` values: - `Unknown` — cannot determine outcome - `Shared` — user selected an app (content was likely shared) - `NotShared` — user dismissed the share sheet without selecting an app ### Method Signature `NativeShare.SetCallback(ShareResultCallback callback)` ### Parameters #### Path Parameters - **callback** (ShareResultCallback) - Required - The callback function to execute after sharing. ### Example ```csharp new NativeShare() .SetText("Hello World!") .SetCallback((ShareResult result, string shareTarget) => { switch (result) { case ShareResult.Shared: Debug.Log($"Shared successfully via: {shareTarget ?? "unknown"}"); // Check if user picked Twitter if (shareTarget != null && shareTarget.ToLowerInvariant().Contains("twitter")) Debug.Log("Shared to Twitter!"); break; case ShareResult.NotShared: Debug.Log("User cancelled sharing."); break; default: Debug.Log("Share result unknown."); break; } }) .Share(); ``` ``` -------------------------------- ### Reset NativeShare Instance Source: https://context7.com/yasirkula/unitynativeshare/llms.txt Clears all previously configured state on an existing NativeShare instance. This is useful for reusing a single instance across multiple share operations to avoid repeated memory allocations. Call Clear() before configuring the instance for a new share. ```csharp NativeShare sharer = new NativeShare(); // First share sharer.SetText("First message").Share(); // Reuse the same instance sharer.Clear() .SetText("Second message") .AddFile(someFilePath) .Share(); ``` -------------------------------- ### Set Shared Text Source: https://context7.com/yasirkula/unitynativeshare/llms.txt Use SetText to provide the body of the shared message. Note that some applications may ignore this text if a file is also being shared. ```csharp new NativeShare() .SetText("Playing this awesome game! Download it here.") .Share(); ``` -------------------------------- ### NativeShare.Clear Source: https://context7.com/yasirkula/unitynativeshare/llms.txt Resets a reusable instance of NativeShare by clearing all previously configured state, including files, text, subject, targets, and callback. This is useful when reusing a single instance across multiple share operations to avoid repeated allocations. ```APIDOC ## `NativeShare.Clear()` ### Description Clears all previously configured state (files, text, subject, targets, callback) on an existing `NativeShare` instance. Useful when reusing a single instance across multiple share operations to avoid repeated allocations. ### Method Signature `NativeShare.Clear()` ### Example ```csharp NativeShare sharer = new NativeShare(); // First share sharer.SetText("First message").Share(); // Reuse the same instance sharer.Clear() .SetText("Second message") .AddFile(someFilePath) .Share(); ``` ``` -------------------------------- ### Pre-fill Email Recipients on Android Source: https://context7.com/yasirkula/unitynativeshare/llms.txt Use AddEmailRecipient to automatically populate the 'To' field for email apps on Android. This method can be called multiple times to add several recipients. ```csharp new NativeShare() .SetSubject("Game Invite") .SetText("Join me in this game!") .AddEmailRecipient("friend@example.com") .AddEmailRecipient("another@example.com") .Share(); ``` -------------------------------- ### NativeShare.SetTitle Source: https://context7.com/yasirkula/unitynativeshare/llms.txt Sets the title displayed at the top of the Android share chooser dialog. Has no effect on iOS. ```APIDOC ## NativeShare.SetTitle(string title) ### Description Sets the title displayed at the top of the Android share chooser dialog. Has no effect on iOS. ### Method ```csharp new NativeShare() .SetTitle("Share via") .SetText("Hello from my Unity game!") .Share(); ``` ``` -------------------------------- ### NativeShare.SetText Source: https://context7.com/yasirkula/unitynativeshare/llms.txt Sets the body text of the share payload. Note: some apps (e.g., Facebook) intentionally ignore text when a file is also present. ```APIDOC ## NativeShare.SetText(string text) ### Description Sets the body text of the share payload. Note: some apps (e.g., Facebook) intentionally ignore text when a file is also present. ### Method ```csharp new NativeShare() .SetText("Playing this awesome game! Download it here.") .Share(); ``` ``` -------------------------------- ### NativeShare.SetSubject Source: https://context7.com/yasirkula/unitynativeshare/llms.txt Sets the subject line for the share action, primarily consumed by email applications. Returns the NativeShare instance for chaining. ```APIDOC ## NativeShare.SetSubject(string subject) ### Description Sets the subject line for the share action, primarily consumed by email applications. Returns the `NativeShare` instance for chaining. ### Method ```csharp new NativeShare() .SetSubject("Check out this screenshot!") .SetText("Here is the screenshot I took.") .Share(); ``` ``` -------------------------------- ### Set Android Share Dialog Title Source: https://context7.com/yasirkula/unitynativeshare/llms.txt Use SetTitle to customize the title displayed in the Android share chooser dialog. This option has no effect on iOS. ```csharp new NativeShare() .SetTitle("Share via") .SetText("Hello from my Unity game!") .Share(); ``` -------------------------------- ### NativeShare.AddEmailRecipient Source: https://context7.com/yasirkula/unitynativeshare/llms.txt Auto-populates the recipients field when the user picks an email app on Android. Has no effect on iOS. Can be called multiple times to add multiple recipients. ```APIDOC ## NativeShare.AddEmailRecipient(string emailAddress) ### Description Auto-populates the recipients field when the user picks an email app on Android. Has no effect on iOS. Can be called multiple times to add multiple recipients. ### Method ```csharp new NativeShare() .SetSubject("Game Invite") .SetText("Join me in this game!") .AddEmailRecipient("friend@example.com") .AddEmailRecipient("another@example.com") .Share(); ``` ``` -------------------------------- ### NativeShare.AddTarget Source: https://context7.com/yasirkula/unitynativeshare/llms.txt Restricts the Android share sheet to a specific application by package name or a specific activity by package and class name. This method can be called multiple times to allow several specific targets. It has no effect on iOS. ```APIDOC ## `NativeShare.AddTarget(string androidPackageName, string androidClassName = null)` ### Description Restricts the Android share sheet to a specific application (by package name) or a specific activity (by package + class name). Can be called multiple times to allow several specific targets. Has no effect on iOS. ### Method Signature `NativeShare.AddTarget(string androidPackageName, string androidClassName = null)` ### Parameters #### Path Parameters - **androidPackageName** (string) - Required - The package name of the Android app. - **androidClassName** (string) - Optional - The class name of the Android activity. ### Example ```csharp // Share to WhatsApp only if it is installed if (NativeShare.TargetExists("com.whatsapp")) { new NativeShare() .AddFile(screenshotPath) .AddTarget("com.whatsapp") .Share(); } else { Debug.Log("WhatsApp is not installed."); } ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.