Skip to content

Instantly share code, notes, and snippets.

@Borod4r
Last active March 11, 2022 02:53
Show Gist options
  • Save Borod4r/b8eec5911913d7e6eac6 to your computer and use it in GitHub Desktop.
Save Borod4r/b8eec5911913d7e6eac6 to your computer and use it in GitHub Desktop.
Share image with text on android (works with FB)
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