Last active
March 11, 2022 02:53
-
-
Save Borod4r/b8eec5911913d7e6eac6 to your computer and use it in GitHub Desktop.
Share image with text on android (works with FB)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static void ShareImageWithTextOnAndroid(string message, string imageFilePath) | |
{ | |
AndroidJavaClass intentClass = new AndroidJavaClass("android.content.Intent"); | |
AndroidJavaObject intentObject = new AndroidJavaObject("android.content.Intent"); | |
intentObject.Call<AndroidJavaObject>("setAction", intentClass.GetStatic<string>("ACTION_SEND")); | |
AndroidJavaClass uriClass = new AndroidJavaClass("android.net.Uri"); | |
AndroidJavaObject uriObject = uriClass.CallStatic<AndroidJavaObject>("parse", "file://" + imageFilePath); | |
intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_STREAM"), uriObject); | |
intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_TEXT"), message); | |
intentObject.Call<AndroidJavaObject>("setType", "image/jpeg"); | |
AndroidJavaClass unity = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); | |
AndroidJavaObject currentActivity = unity.GetStatic<AndroidJavaObject>("currentActivity"); | |
currentActivity.Call("startActivity", intentObject); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment