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

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.