- Home /
Share text message on selected media
I want to share text data on player selected social media. Basically I want to implement functionality like following link represent for android.
I want to give user a choice for sharing on Twitter, Facebook, Messaging, Gmail etc. Above link give proper guidance for my question.
Here is code that work on android
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
sendIntent.setType("text/plain");
startActivity(sendIntent);
I don't know same functionality implementation in Unity. Basically at present I am targeting two platform for my game
Android
iOS
Now I think my question is clear to all of you. So please help me to solve it.
I need some help for this. I only want to know, In Unity, Can I able to core android code?
This should get you started on running your java code form unity http://docs.unity3d.com/$$anonymous$$anual/PluginsForAndroid.html
I am looking for similar answer for iOS. Anybody know about this.
here is the code for screen shot but i need for text
AndroidJavaClass intentClass = new AndroidJavaClass("android.content.Intent"); AndroidJavaObject intentObject = new AndroidJavaObject("android.content.Intent"); intentObject.Call("setAction", intentClass.GetStatic("ACTION_SEND")); AndroidJavaClass uriClass = new AndroidJavaClass("android.net.Uri"); AndroidJavaObject uriObject = uriClass.CallStatic("parse","file://" + destination); intentObject.Call("putExtra", intentClass.GetStatic("EXTRA_STREA$$anonymous$$"), uriObject); //intentObject.Call("putExtra", intentClass.GetStatic("EXTRA_TEXT"), "testo"); //intentObject.Call("putExtra", intentClass.GetStatic("EXTRA_SUBJECT"), "SUBJECT"); intentObject.Call("setType", "image/jpeg"); AndroidJavaClass unity = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); AndroidJavaObject currentActivity = unity.GetStatic("currentActivity"); currentActivity.Call ("startActivity", intentObject);
Answer by Mayank Ghanshala · Aug 18, 2014 at 01:01 PM
Dont know for IOS but for android you can..
AndroidJavaClass intentClass = new AndroidJavaClass ("android.content.Intent");
AndroidJavaObject intentObject = new AndroidJavaObject ("android.content.Intent");
intentObject.Call<AndroidJavaObject> ("setAction", intentClass.GetStatic<string> ("ACTION_SEND"));
intentObject.Call<AndroidJavaObject> ("setType", "text/plain");
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.");
AndroidJavaClass unity = new AndroidJavaClass ("com.unity3d.player.UnityPlayer");
AndroidJavaObject currentActivity = unity.GetStatic<AndroidJavaObject> ("currentActivity");
currentActivity.Call ("startActivity", intentObject);
Thanks @$$anonymous$$ayank, I will check it and reply you shortly. For above code, where I have to write it?
in your script . write them in a method and call it on your share button click. Actually AndroidJavaClass is used to access android methods in unity. You can find more on this.
Welcome any time. I don't know about IOS but if I will find I will paste here soon.
its not working for android i want to share text but its not working... if i want to share screen shot its working
Your answer
Follow this Question
Related Questions
Executing native iOS code in Unity 1 Answer
Share image on selected media 1 Answer
A node in a childnode? 1 Answer
Game Center login windows popups after hiding an app 0 Answers