• 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 Denscrivent · Dec 17, 2015 at 10:21 AM · androidunity5

Unity Android ScreenShot Error Sharing to Apps

SOLVED! See Answers below.

Hi everyone!

I've been looking for answers everywhere but I couldn't find it.

I'm trying to take a screenshot and upload it to apps. Here's my code

 public void TakeScreenShot(GameObject a){
         Vector3 ScreenShotPos = new Vector3(1.7f,-6.95f,0f);
         ssName = "PIXMA.png";
 
         if (a != null)
             CharaForScreenShot = a;
 
         temp = GameObject.Instantiate(CharaForScreenShot,ScreenShotPos,CharaForScreenShot.transform.rotation) as GameObject;
     
         path = Path.Combine(Application.persistentDataPath,ssName);
         print (path);
 
         //delay for screenshot
         StartCoroutine(TakeScreenShot());
 
     }
 
     IEnumerator TakeScreenShot() {
         // We should only read the screen buffer after rendering is complete
         yield return new WaitForEndOfFrame();
         
         // Create a texture the size of the screen, RGB24 format
         int width = Screen.width;
         int height = Screen.height;
         Texture2D 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();
         
         // Encode texture into PNG
         byte[] bytes = tex.EncodeToPNG();
         Object.Destroy(tex);
 
         // For testing purposes, also write to a file in the project folder
         File.WriteAllBytes(path, bytes);
         
         StartCoroutine(wait(3));
         
     }
 
     private IEnumerator wait(int waitTime){
         yield return new WaitForSeconds(waitTime);
 
         if( File.Exists(path) ) {//file exist
             WWW loadedImage = new WWW("file://"+path);
             if (temp != null) Destroy(temp);
             SSImg.texture = loadedImage.texture;
             CollectionSceneHandler.instance.waitToShare(path);
             CollectionSceneHandler.instance.DisableScreenShotCamera();
 
 
         }else{//file doesn't exist
             print ("file not exist");
         }


and I got codes below from http://www.daniel4d.com/blog/sharing-image-unity-android/

 IEnumerator ShareToInstalledApps(string path){
         yield return new WaitForSeconds(3);
 
         //instantiate the class Intent
         AndroidJavaClass intentClass = new AndroidJavaClass("android.content.Intent");
         
         //instantiate the object Intent
         AndroidJavaObject intentObject = new AndroidJavaObject("android.content.Intent");
         
         //call setAction setting ACTION_SEND as parameter
         intentObject.Call<AndroidJavaObject>("setAction", intentClass.GetStatic<string>("ACTION_SEND"));
         
         //instantiate the class Uri
         AndroidJavaClass uriClass = new AndroidJavaClass("android.net.Uri");
         
         //instantiate the object Uri with the parse of the url's file
         AndroidJavaObject uriObject = uriClass.CallStatic<AndroidJavaObject>("parse","file://"+path);
         
         //call putExtra with the uri object of the file
         intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_STREAM"), uriObject);
         
         //set the type of file
         intentObject.Call<AndroidJavaObject>("setType", "image/jpeg");
         
         //instantiate the class UnityPlayer
         AndroidJavaClass unity = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
         
         //instantiate the object currentActivity
         AndroidJavaObject currentActivity = unity.GetStatic<AndroidJavaObject>("currentActivity");
         
         //call the activity with our Intent
         currentActivity.Call("startActivity", intentObject);
     }

the screenshot work well,. The Image shows when I call it using WWW.

The problem is whenever I try to share the image. it always gets an error.

Please help!

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Denscrivent · Dec 17, 2015 at 10:34 AM

SOLVED!

DO NOT FORGET to Grant the Writing Access to External (SDCard) in PlayerSettings (Other Settings), otherwise you won’t be able to share pictures.

It is also provided in the website.

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 GiyomuGames · Jun 03, 2016 at 01:45 AM 0
Share

You my friend just saved me from a headache ^^

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

39 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 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

Unity5.4.0p4 compile error for android by il2cpp 1 Answer

Failure [INSTALL_FAILED_CPU_ABI_INCOMPATIBLE] (solved) 1 Answer

Why does my pause & quit menus appear when I load next level? 0 Answers

Sound Lag in unity game made for android 0 Answers

Unity 3D split apk not loading the .OBB file 0 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