- Home /
Share image on selected media
I want to share image on selected media that I capture through code.
At present I have following code to capture image
private void CaptureScreenShot()
{
Texture2D tex = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);
if (tex != null)
{
tex.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0, false);
tex.Apply();
var bytes = tex.EncodeToPNG();
if (bytes.Length > 0)
{
Debug.Log("Texture got");
SaveTextureToFile(tex,"text.png");
}
}
}
private void SaveTextureToFile(Texture2D tex,string fileName)
{
var bytes = tex.EncodeToPNG();
var file = File.Open(pathToImage,FileMode.Create);
var binary = new BinaryWriter(file);
binary.Write(bytes);
file.Close();
}
Code for sharing image through intent
AndroidJavaClass intentClass = new AndroidJavaClass("android.content.Intent");
AndroidJavaObject intentObject = new AndroidJavaObject("android.content.Intent");
intentObject.Call<AndroidJavaObject>("setAction", intentClass.GetStatic<string>("ACTION_SEND_MULTIPLE"));
intentObject.Call<AndroidJavaObject>("setType", "*/*");
intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_SUBJECT"), "SUBJECT");
intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_TEXT"), "This is my text to send.");
intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_STREAM"), new Uri(pathToImage).LocalPath);
AndroidJavaClass unity = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject currentActivity = unity.GetStatic<AndroidJavaObject>("currentActivity");
currentActivity.Call("startActivity", intentObject);
Above code not able to work for me. Only text message is pass through social media.
I referenced following link to share image Problems sharing combined text and image with SHARE INTENT on Twitter
Please give some advice in this.
At present, I can't able to attach image in above code. I have tried all the options as per my knowledge.
var uri = new System.Uri(Screenshot$$anonymous$$anager.savedImagePath);
ArrayList uriList = new ArrayList();
uriList.Add(uri);
intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<ArrayList>("EXTRA_STREA$$anonymous$$"), uriList);
//intentObject.Call<AndroidJavaObject>("putParcelableArrayListExtra", intentClass.Get<System.Uri>("EXTRA_STREA$$anonymous$$"), uri);
Please give some suggestions in this.
Answer by GluedBrain · Sep 13, 2015 at 06:33 AM
This post explains how to share image to Social media
http://www.thegamecontriver.com/2015/09/unity-share-post-image-to-facebook.html
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Calling an android method from Unity3D with a JAR plugin 0 Answers
Share text message on selected media 1 Answer
Need clarification in facebook app developer page 0 Answers
Unity games and web comunication 1 Answer