Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 sagiv_bg · May 17, 2016 at 06:52 PM · androidscreenshotnativeshareintent

Android Native share (intent) an image with a link

Hi, I'm trying to share via the android native sharing service a screenshot + a link to my application. The screenshot part is working perfectly though i don't see the text (tried to share with Facebook, twitter and whatsapp).

Here is my code (mostly taken from here):

 public IEnumerator ShareScreenshot(string extraSubject, string extraText)
 {
     isProcessing = true;
     // wait for graphics to render
     yield return new WaitForEndOfFrame();
     
     // create the texture
     var width = Screen.width;
     var height = Screen.height;
     var tex = new Texture2D(width, height, TextureFormat.RGB24, false);
     // Read screen contents into the texture
     tex.ReadPixels(new Rect(0, 0, width, height), 0, 0);
     tex.Apply();
    
     byte[] dataToSave = tex.EncodeToPNG();
     string destination = Path.Combine(Application.persistentDataPath, System.DateTime.Now.ToString("yyyy-MM-dd-HHmmss") + ".png");
     File.WriteAllBytes(destination, dataToSave);
     if (!Application.isEditor)
     {
         // block to open the file and share it ------------START
         AndroidJavaClass intentClass = new AndroidJavaClass("android.content.Intent");
         AndroidJavaObject intentObject = new AndroidJavaObject("android.content.Intent");
         intentObject.Call<AndroidJavaObject>("setAction", intentClass.GetStatic<string>("ACTION_SEND"));
         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", "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"), extraSubject);
         intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_TEXT"), extraText);

         intentObject.Call<AndroidJavaObject>("setType", "image/jpeg");
         AndroidJavaClass unity = new AndroidJavaClass("com.unity3d.player.UnityPlayer");

         AndroidJavaObject jChooser = intentClass.CallStatic<AndroidJavaObject>("createChooser", intentObject, "Share Via");
         AndroidJavaObject currentActivity = unity.GetStatic<AndroidJavaObject>("currentActivity");
         currentActivity.Call("startActivity", jChooser);
     }

     isProcessing = false;
     buttonShare.enabled = true;
     ButtonRestart.enabled = true;
 }


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 · May 18, 2016 at 07:17 AM 0
Share

Facebook totally restricted this kind of sharing. You need to sign in into facebook account to perform this kind of sharing. I don't know about Twitter and Whatsapp. $$anonymous$$ay be they also follow same strategy now. Some time ago for Twitter working for me, text and image sharing.

4 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by hybridAli · May 01, 2017 at 09:41 AM

I have a blog post about what you need http://alihc.me/unity-3d-native-nativeshare/

Comment
Add comment · Show 1 · 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
avatar image schlenger · Jun 19, 2020 at 09:34 AM 0
Share

This link is broken. Please remove it or update it. Thanks

avatar image
0

Answer by Shasha1110 · Oct 10, 2017 at 11:40 AM

Hi , I have followed this code for snapshot sharing. It works fine except 7.0 devices. The intent chooser option window doesn't open in 7.0 and above devices. Can anybody guide me how to resolve this? Thanks in advance .

Comment
Add comment · Show 1 · 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
avatar image Amirjaouani · Oct 03, 2018 at 10:53 AM 0
Share

Hy, i have the same problem, did you find any soluton?

Thanks!

avatar image
0

Answer by SmileSoft4849 · Mar 18, 2018 at 04:49 AM

I have Created a Unity Android share plugins which can share both Images and video files and support almost all Android versions. You can Check out it from the asset store.
Link : https://assetstore.unity.com/packages/tools/integration/android-native-share-127249

Comment
Add comment · Show 1 · 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
avatar image junedmmn · Apr 19, 2019 at 06:42 PM 0
Share

@SmileSoft4849, You must help users by providing appropriate answers, ins$$anonymous$$d you are marketing your useless products so that you get money while we purchase your asset. This is users community, not your market place. Please bear that in $$anonymous$$d.

For those having issue with Native Sharing get this code. It helped me a lot Get source code from here https://gist.github.com/agrawalsuneet/a39cdbee9fa093a16b817742b602f9e7

For Reference Go to https://medium.com/@agrawalsuneet/native-android-screenshot-image-sharing-in-unity-47eda326b80c

I do not know if it works in Android Oreo or later, mention if you find it working in Android Oreo or later.

avatar image
0

Answer by junedmmn · Apr 19, 2019 at 06:47 PM

For those who didn't find the answer try this code. It worked for me.


Get Source Code from https://gist.github.com/agrawalsuneet/a39cdbee9fa093a16b817742b602f9e7

For reference go to https://medium.com/@agrawalsuneet/native-android-screenshot-image-sharing-in-unity-47eda326b80c

Please mention, if it works in Android Oreo or later.

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

10 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

Related Questions

NoSuchMethodError when calling putExtra 0 Answers

Facebook app review for screenshot share 0 Answers

Share screen and text on social media 1 Answer

Open Android App from URL 3 Answers

Share image in Unity Game on Android devices error 2 Answers


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