- Home /
This question was
closed Nov 07, 2016 at 06:07 PM by
haiderInUnity for the following reason:
The question is answered, right answer was accepted
Question by
haiderInUnity · Nov 06, 2016 at 09:51 PM ·
screenshotnativesharesocial
Share screen and text on social media
Hi I have this code that works on one of my game but on the other game the picture is not being taken but the text is there. when i try to send it on for example watsapp then error occours saying "sending failed try again later" can you tell me what could be causing this?
public void shareScreen ()
{
Texture2D MyImage = new Texture2D (Screen.width, Screen.height, TextureFormat.RGB24, true);
MyImage.ReadPixels (new Rect (0f, 0f, Screen.width, Screen.height), 0, 0);
MyImage.Apply ();
byte[] bytes = MyImage.EncodeToPNG ();
string path = Application.persistentDataPath + "/MyImage.png";
File.WriteAllBytes (path, bytes);
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://" + path);
intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_STREAM"), uriObject);
intentObject.Call<AndroidJavaObject> ("setType", "text/plain");
intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_TITLE"),"Color Shoot");
intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_TEXT"), "" + "My Score " + gc.score);
intentObject.Call<AndroidJavaObject>("setType", "image/jpeg");
AndroidJavaClass unity = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject currentActivity = unity.GetStatic<AndroidJavaObject>("currentActivity");
currentActivity.Call("startActivity", intentObject);
}
Comment
Best Answer
Answer by haiderInUnity · Nov 07, 2016 at 06:06 PM
Ok i found out what the issue was. In build settings -> player settings -> other settings -> write access needed to be external(Sd)