Share pictures and text to friends in the Android app
You need to add the permission to read and write sdcard to the configuration file.
Using UnityEngine; using System. collections; using System. IO; public class Share: MonoBehaviour {public static string imagePath; static AndroidJavaClass extends pluginclass; static AndroidJavaClass unityPlayer; static AndroidJavaObject currActivity; private static Share mInstance; public static Share instance {get {return mInstance ;}} void Awake () {mInstance = this;} void Start () {imagePath = Application. persistentDataPath +/HKeyGame.png; export pluginclass = new AndroidJavaClass (com. ari. tool. unityAndroidTool); if (export pluginclass = null) {Debug. log (writable pluginclass is null);} else {Debug. log (writable pluginclass is not null);} unityPlayer = new AndroidJavaClass (com. unity3d. player. unityPlayer); currActivity = unityPlayer. getStatic (currentActivity);} public void CallShare (string handline, string subject, string text, bool image) {Debug. log (share call start: + imagePath); if (image) {sharePluginClass. callStatic (share, new object [] {handline, subject, text, imagePath});} else {shareinclass. callStatic (share, new object [] {handline, subject, text,});} Debug. log (share call end);} public void ScreenShot () {StartCoroutine (GetCapture ();} IEnumerator GetCapture () {yield return new WaitForEndOfFrame (); int width = Screen. width; int height = Screen. height; Texture2D tex = new Texture2D (width, height, TextureFormat. RGB24, false); tex. readPixels (new Rect (0, 0, width, height), 0, 0, true); byte [] imagebytes = tex. encodeToPNG (); // convert to png graph tex. compress (false); // compresses the screen cache // image. mainTexture = tex; // display the screen cache (thumbnail) File. writeAllBytes (Application. persistentDataPath +/HKeyGame.png, imagebytes); // stores the png Image Debug. log (Application. persistentDataPath );}}