- Home /
Question by
JPsLucky13 · Sep 18, 2015 at 12:36 PM ·
androidemailsharingsms
How to avoid Unity from reloading the game when completing a share function from android?
Hello all! I am having a lot of trouble with sharing message (SMS, EMAIL,etc..) on a game I am currently working on. The main issue is that when I share a custom made text message on my android phone which includes an image, the game reloads. I would want the game to stay where it was before I open an sms or email app box to send the message.
Here is the code I am using for sharing text and images:
//Reference of AndroidJavaClass class for intent
AndroidJavaClass intentClass = new AndroidJavaClass ("android.content.Intent");
//Reference of AndroidJavaObject class for intent
AndroidJavaObject intentObject = new AndroidJavaObject ("android.content.Intent");
//call setAction method of the Intent object created
intentObject.Call<AndroidJavaObject> ("setAction", intentClass.GetStatic<string> ("ACTION_SEND"));
//set the type of sharing that is happening
intentObject.Call<AndroidJavaObject> ("setType", "text/plain");
//add data to be passed to the other activity i.e., the data to be sent
intentObject.Call<AndroidJavaObject> ("putExtra", intentClass.GetStatic<string> ("EXTRA_SUBJECT"), subject);
body += GameManager.instance.highestAmountSteps.ToString() + " score!";
intentObject.Call<AndroidJavaObject> ("putExtra", intentClass.GetStatic<string> ("EXTRA_TEXT"), body);
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>("setType", "image/png");
//get the current activity
AndroidJavaClass unity = new AndroidJavaClass ("com.unity3d.player.UnityPlayer");
AndroidJavaObject currentActivity = unity.GetStatic<AndroidJavaObject> ("currentActivity");
//start the activity by sending the intent data
currentActivity.Call ("startActivity", intentObject);
Would very much appreciate the help!
Comment