# Can't save Screenshot to Android

so I have a method for taking a screenshot, it works just fine on PC, but I've tried everything and cannot get it to work on Android. I've tried creating custom folders, saving to persistentDataPath, saving to dataPath, and none of it works.

I had a way of testing it which said the name of the screenshot, logically it should keep the name as screenshot1 if it fails to take the screenshot, which it does on mobile, whereas the one on desktop increments properly.

Here's the method I most recently attempted...

    public void captureScreenshot(string name)
{
if (!countDown)
{
for (int i = 1; i < 500; i++)
{

if (!File.Exists(Application.dataPath + name + i + ".png"))
{
if (!Directory.Exists(Application.dataPath + "/appScreenshots"))
{
Directory.CreateDirectory(Application.dataPath + "/appScreenshots");
}
ScreenCapture.CaptureScreenshot(Application.dataPath + name + i + ".png");
break;
}
}
}
}

public void captureScreenshot(string name)
{
if (!countDown)
{
for (int i = 1; i < 500; i++)
{

if (!File.Exists(Application.dataPath + name + i + ".png"))
{
if (!Directory.Exists(Application.dataPath + "/appScreenshots"))
{
Directory.CreateDirectory(Application.dataPath + "/appScreenshots");
}
ScreenCapture.CaptureScreenshot(Application.dataPath + name + i + ".png");
break;
}
}
}
}


So, it works just fine on PC, just not on mobile... Do I need to get special permissions or something?

Thanks

• The documentation for ScreenCapture.CaptureScreenshot mentions that on mobile the filename parameter is appended to Application.persistentDataPath. Have you tried with just the filename?
– user35344
May 4, 2021 at 10:25
• I just tried that now, but it's still not saving properly. Again I added a line to print of the screenshot name, it increments on Pc but not on mobile. May 4, 2021 at 10:43
• Application.dataPath is not a writeable location on mobile. Did you mean to use persistentDataPath? It also looks to me like you might be missing a slash between your path and your file name, and you're not using the appScreenshots folder you're creating. Is the directory created as expected when using persistentDataPath? May 4, 2021 at 11:35
• Yeah, I've tried both. And I noticed the slash, there's actually a slash in the "name" string. May 4, 2021 at 16:30
• So just to clarify, just having ScreenCapture.CaptureScreenshot("Test") somewhere does not produce any output for you on Android?
– user35344
May 6, 2021 at 6:43

Well, I fixed it. I think the issue was that I had a / in the name, I tried test but nothing happened, so i tried just "Screenshot.png" and it worked, now it's taking screenshots. Here's the updated code,

        public void captureScreenshot(string name)
{

for (int i = 1; i < 500; i++)
{

if (!File.Exists(Application.persistentDataPath + "/Screenshot.png" + (i + 1)))
{
ScreenCapture.CaptureScreenshot("Screenshot" + (i + 1)+".png");

text.GetComponent<TextMeshProUGUI>().text = name + i + ".png";
break;
}

}
}

• You probably want the (i + 1) before the .png - maybe like \$"Screenshot{i + 1}.png" instead. May 7, 2021 at 13:57
• Thank you, I should've posted after I fixed that haha. May 10, 2021 at 10:44
• It's still not too late to fix it now. Also, don't forget to click the checkmark icon to mark this answer as "Accepted" if it worked for you. Oct 4, 2021 at 11:03