- Home /
Question by
deimostudios · Oct 30, 2015 at 09:16 PM ·
2d gamefacebooksharing
Game restarts after Facebook sharing (share intent)
Hi,
After sharing a screenshot on Facebook using a share intent, the game is restarted. If I don't share and taps ESC, the game is still running. If a share using Gmail, works fine. Any ideas? Thanks!
Please see the code:
public void ShareIntent()
{
// Screenshot
Texture2D texture = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);
texture.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0);
texture.Apply();
// Persist
byte[] dataToSave = texture.EncodeToPNG();
string destination = Path.Combine(Application.persistentDataPath, "screenshot.png");
File.WriteAllBytes(destination, dataToSave);
// Set up the Intent
AndroidJavaClass intentClass = new AndroidJavaClass("android.content.Intent");
AndroidJavaObject intentObject = new AndroidJavaObject("android.content.Intent");
intentObject.Call<AndroidJavaObject>("setAction", intentClass.GetStatic<string>("ACTION_SEND"));
// Create the message
AndroidJavaClass uriClass = new AndroidJavaClass("android.net.Uri");
AndroidJavaObject uriObject = uriClass.CallStatic<AndroidJavaObject>("parse", "file://" + destination);
intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_STREAM"), uriObject);
intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_SUBJECT"), "New score!");
intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_TEXT"), "Check this out!");
intentObject.Call<AndroidJavaObject>("setType", "image/png");
// Call the Activity
AndroidJavaClass unity = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject currentActivity = unity.GetStatic<AndroidJavaObject>("currentActivity");
currentActivity.Call("startActivity", intentObject);
}
Comment
Well, I've just checked and found the exact same issue in #crossyroad
Your answer
Follow this Question
Related Questions
Sharing a photo in facebook, how to get facebook photo by ID? 0 Answers
FaceBook SDK 0 Answers
Share an Image on Faceook 2 Answers
Share score on facebook *Without facebook SDK* (ANDROID) 2 Answers