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 Javaisland · Feb 17, 2017 at 10:04 PM · android2d gameapplicationblackscreencapturescreenshot

Android Native Screenshot function creats black Image

Hello Guys,

as written in the header I'm facing this weird problem that the Project is producing a black Screenshot when the native Android button combination is used (soundwhip + homebutton). Does anybody know why this happens? Does anybody know how I can enable the native screenshot function?

I added a script to make screenshots possible thru an UI Button on the GUI of the game but somehow the image is always kept in the Application.persistancepath even when the script tries to change its location.

  public void CaptureScreenshot()
     {
  
         StartCoroutine(TakeScreenshot());
 
     }
 
     private IEnumerator TakeScreenshot()
     {
         yield return new WaitForEndOfFrame();
 
         //INITIAL SETUP
         screenShotCount++;
         string myFilename ="screenshot" + screenShotCount + ".png";
         string myDefaultLocation = Application.persistentDataPath + "/" + myFilename;
         //EXAMPLE OF DIRECTLY ACCESSING THE Camera FOLDER OF THE GALLERY
         //string myFolderLocation = "/storage/emulated/0/DCIM/Camera/";
         //EXAMPLE OF BACKING INTO THE Camera FOLDER OF THE GALLERY
         //string myFolderLocation = Application.persistentDataPath + "/../../../../DCIM/Camera/";
         //EXAMPLE OF DIRECTLY ACCESSING A CUSTOM FOLDER OF THE GALLERY
         string myFolderLocation = "/sdcard/DCIM/screenshotUnity/";
         string myScreenshotLocation = myFolderLocation + myFilename;
         
         //ENSURE THAT FOLDER LOCATION EXISTS
         if (!System.IO.Directory.Exists(myFolderLocation))
         {
             System.IO.Directory.CreateDirectory(myFolderLocation);
         }
         //TAKE THE SCREENSHOT AND AUTOMATICALLY SAVE IT TO THE DEFAULT LOCATION.
         Application.CaptureScreenshot(myFilename);
         //MOVE THE SCREENSHOT WHERE WE WANT IT TO BE STORED
         System.IO.File.Move(myDefaultLocation, myScreenshotLocation);
         //REFRESHING THE ANDROID PHONE PHOTO GALLERY IS BEGUN
         AndroidJavaClass classPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
         AndroidJavaObject objActivity = classPlayer.GetStatic<AndroidJavaObject>("currentActivity");
         AndroidJavaClass classUri = new AndroidJavaClass("android.net.Uri");
         AndroidJavaObject objIntent = new AndroidJavaObject("android.content.Intent", new object[2] { "android.intent.action.MEDIA_MOUNTED", classUri.CallStatic<AndroidJavaObject>("parse", "file://" + myScreenshotLocation) });
         objActivity.Call("sendBroadcast", objIntent);
         //REFRESHING THE ANDROID PHONE PHOTO GALLERY IS COMPLETE
 
         //AUTO LAUNCH/VIEW THE SCREENSHOT IN THE PHOTO GALLERY
         //Application.OpenURL(myScreenshotLocation);
         //AFTERWARDS IF YOU MANUALLY GO TO YOUR PHOTO GALLERY, 
         //YOU WILL SEE THE FOLDER WE CREATED CALLED "myFolder"
     }

thank you

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 Javaisland · Feb 17, 2017 at 03:36 PM 0
Share

I still confronted with this Problem, would be nice if anyone had an answer....

1 Reply

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

Answer by MEDIALLIANCE_2 · Mar 06, 2017 at 03:22 PM

Hey, I think everyone struggles with screencapture on mobile devices... It's also melting my brain...

Anyway, here, you do'nt use Android Native function, you use Application.CaptureScreenshot(myFilename); and then you move the file to your desired location. The Android part is for updating the Photo Gallery (which doesn't work for me BTW).

Black screenshots seems to appear because of antialiasing. Try to remove it first to check if the issue is still here. I managed to find a workaround by checking the file size when created (black pictures are low sized), delete it and try again until completion. I had a limit where I removed antialiasing. File Size-Checking:

 FileInfo fileInfo = new System.IO.FileInfo (sourcePath);
 if (fileInfo.Length < 150000) { File.Delete (sourcePath); }

Hope this helps.

Comment
Add comment · Show 5 · 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 Javaisland · Mar 06, 2017 at 03:46 PM 0
Share

Thank you for your answer, I somehow managed to get the Screen capture going, the biggest Problem since today is that the Script won't move the Image into the Gallery folder /DCI$$anonymous$$, and it also won't refresh the Gallery so the Images can be shown.

This made me so frustrated that I just cancelled the Screen capture Functionality out of my Project, and after Updating to API Level 14 the Native Screen capture of Android started working properly. I just think I had something wrong in the Project Settings. I uploaded my Game to the Google PlayStore 2 weeks ago.

avatar image MEDIALLIANCE_2 Javaisland · Mar 06, 2017 at 03:57 PM 0
Share

I'm facing the exact same problem with Gallery update. Not a single solution on the Internet works completely. Some assetstore packages/plugins seems to manage to do it. But I'm trying not to use plugin, since I'm facing problem when I got two running at the same time... I'm actually trying to use the Android Native takeScreenshot function. http://stackoverflow.com/questions/36385180/xamarin-android-take-screenshot

avatar image MEDIALLIANCE_2 Javaisland · Mar 23, 2017 at 12:40 PM 0
Share

I finally bought this assets from the assetstore. It works fine on Android from screencapture and gallery update. You can also change the folder where the captures are taken (else it's the persistentDataPath)

avatar image Javaisland MEDIALLIANCE_2 · Mar 23, 2017 at 12:48 PM 0
Share

thank you very much, that seems to be a good asset for the screencapture function

Show more comments

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

6 People are following this question.

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

Related Questions

Why experimental 2D Light not working on android? 1 Answer

How do i stop mUnityPlayer.quit() closing the entire android app? 1 Answer

LitJSON android problem 1 Answer

Unity 2018.2 LWRP blackscreen on build(Android VR) 2 Answers

Portrait Android app? 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