- Home /
The question is answered, right answer was accepted
Android CaptureScreenshot not working
Been trying to get the Application.CaptureScreenshot(), on Android, for the last few days, and I can not get it to work.
I have a button set up, already made in the Canvas, with a method attached to the OnClick() events in the editor.
public void ClickScreenshot()
{
snapshotStatus = true;
}
Then an IF statement, in the LateUpdate() method will recognize the boolean change:
void LateUpdate()
{
if (snapshotStatus)
{
StartCoroutine(CaptureScreen());
snapshotStatus = false;
}
}
Which will go to this IEnumerator method to check if the file exists:
private IEnumerator CaptureScreen()
{
string screenshot = System.DateTime.Now.ToString("yyyyMMddHHmmss") + ".png";
string filePath = System.IO.Path.Combine(Application.persistentDataPath, screenshot);
Debug.Log(screenshot);
Debug.Log(Application.persistentDataPath);
// Wait for screen rendering to complete
Application.CaptureScreenshot(screenshot);
while (!File.Exists(filePath))
{
Debug.Log("Sanky: File exist at location" + filePath);
yield return 0;
}
}
This was from looking at other questions from this site, and I still can not get any screenshots to be made. I do not get any com.projectname.app folder made with any screenshots in the file folder, or anything. Tried using Write Access Internal and External (though this device does not have a SD Card slot).
I originally had just the Application.CaptureScreenshot() in the ClickScreenshot() method, but I am at this point pulling straws for anything. Any suggestions?
By the way, when testing on the PC, the original method above works just fine.
Answer by jtrpka0912 · Mar 23, 2017 at 07:26 PM
Turns out the screenshots are inside a directory that can not be accessed w/o using a file manager.