Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by siddharth3322 · Sep 03, 2014 at 11:03 AM · androidsocialsharing

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.

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image siddharth3322 · Oct 09, 2014 at 07:19 AM 0
Share

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.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

23 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges