2
\$\begingroup\$

I'm using CaptureScreentshot() to get an image. But when I try to access it on an Android device it's giving me: Could not find file "/storage/emulated/0/Android/data/appname/screenshot.png"

When I go the external storage, it's not there, but rather on the phone storage. So why is persistentdatapath accessing something different?

My code is the following: byte[] Bytes_File = System.IO.File.ReadAllBytes(currentScreenshotPathname); with thepathname obtained using: currentScreenshotPathname = System.IO.Path.Combine(Application.persistentDataPath, currentScreenshotName);

Is there anyway to make the persistenDataPath go to the phone storage rather than emulated to read the file? I've tried changing the WriteAccess perimission to Externalas well as Internal in the player settings, but it's still the same.

Edit: Here's what's happening: PersistentDataPath is /storage/emulated/0/Android/data/myapp/files/, but the screenshot is being saved to /mnt/sdcard/Android/data/myapp/files, despite the documentation saying that it should save to the PersistentDataPath.

\$\endgroup\$
  • \$\begingroup\$ Have your tried adding it as a resource, then getting its uri? I'm not sure how to do it, but I know that Android doesn't like it when you use file paths. \$\endgroup\$ – ZEKE Nov 23 '15 at 18:09
  • \$\begingroup\$ The thing is, the documentation says it's being saved to Application.persistentDataPath, but it's not. I'm not sure if this is a bug in Unity or not.. \$\endgroup\$ – Pat Nov 23 '15 at 18:29
  • 1
    \$\begingroup\$ PersistentDataPath is /storage/emulated/0/Android/data/myapp/files/, but instead it's being saved to /mnt/sdcard/Android/data/myapp/files. \$\endgroup\$ – Pat Nov 23 '15 at 18:32
1
\$\begingroup\$

Why not using a custom method to take screenshots and save them wherever you want ?

I use this method in my games:

    private IEnumerator TakeScreenshot(string screen_path)
    {
        yield return new WaitForEndOfFrame();

        int width = Screen.width;
        int height = Screen.height;
        // Creates a new texture of the size of your screen.
        Texture2D tex = new Texture2D(width, height, TextureFormat.RGB24, false);
        // Reads every pixel displayed on the screen.
        tex.ReadPixels(new Rect(0, 0, width, height), 0, 0);
        tex.Apply();

        // Save the screenshot as a byte array.
        byte[] bytes = tex.EncodeToPNG();
        Destroy(tex);
        // Save the screenshot on disk.
        File.WriteAllBytes(screen_path, bytes);
        Debug.Log("Screenshot (" + screen_path + ") saved!");
    }

I hope it helps.

\$\endgroup\$
  • 1
    \$\begingroup\$ Yes, I switched to using something similar. I'm going to accept your response in case someone else has that problem. :D \$\endgroup\$ – Pat Nov 27 '15 at 8:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.