- Home /
How to send multiple screenshots to the android intent(Social networks - Mail, WhatsApp, Hangouts, Facebook ...etc)
Hello, I am sucked with sending multiple screen shots to the android social intent. I have checked all those sites for sending multiple attachments to the mail, but it did not works for me. I have shared a screen shot that what i have written for multiple file attachments. Can anyone help me to come out from this. Thanks for the viewing! Thanks.
Advance Merry Christmas
Answer by dkh031990 · Sep 13, 2018 at 11:33 AM
Here is a perfect solution for multiple file sharing in android:
List pathsList = new List();
//add file path in in list
foreach (FileInfo fileInfo in GifPriviewHandler.instance.fileInfo)
{
pathsList.Add(GifPriviewHandler.instance.globalPath + fileInfo.Name);
}
AndroidJavaClass intentClass = new AndroidJavaClass("android.content.Intent");
AndroidJavaObject intentObject = new AndroidJavaObject("android.content.Intent");
intentObject.Call<AndroidJavaObject>("setType", "image/*");
intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_TEXT"), "Created using Text Animation App");
intentObject.Call<AndroidJavaObject>("setAction", intentClass.GetStatic<string>("ACTION_SEND_MULTIPLE"));
AndroidJavaObject list = new AndroidJavaObject("java.util.ArrayList");
foreach (string path in pathsList)
{
AndroidJavaClass uriClass = new AndroidJavaClass("android.net.Uri");
// get Uri from path and it in a list which list will be pass to android classes.
AndroidJavaObject uriObject = uriClass.CallStatic<AndroidJavaObject>("parse", path);
//THIS IS MOST IMPORTANT PART.
// we must need to pass "bool" in Call function. if you not declare bool here, "Signature" error you will get from android side.
//"add" it is a method name in java list class to add data in a list.
list.Call<bool>("add", uriObject);
}
// for multiple file sharing we need "putParcelableArrayListExtra" key.
intentObject.Call<AndroidJavaObject>("putParcelableArrayListExtra", intentClass.GetStatic<string>("EXTRA_STREAM"), list);
AndroidJavaClass unity = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject currentActivity = unity.GetStatic<AndroidJavaObject>("currentActivity");
AndroidJavaObject chooser = intentClass.CallStatic<AndroidJavaObject>("createChooser", intentObject, "Share your File");
currentActivity.Call("startActivity", chooser);
Answer by Altaf-N · Dec 16, 2020 at 07:17 PM
Works perfectly fine for sharing via WhatsApp, But unable to attach the file via email. Any solution for that?
Thanks you!
Your answer
Follow this Question
Related Questions
Unity Android java.lang.ClassNotFoundException 1 Answer
How to handle an intent from another Android App in Unity? 1 Answer
AndroidJava and Implementing java.util.List 0 Answers
Unity can't receive information from Intent *urgent 0 Answers
Android plugin & Activity help needed - "GetMethodID method not found" problems 0 Answers