Can't save screenshot into persistentDataPath
I use this code public static string MakeScreenShot() {
string directoryPath =Path.Combine(Application.persistentDataPath ,"Screenshots");
if(!Directory.Exists(directoryPath))
{
//if it doesn't exist, create it
Directory.CreateDirectory(directoryPath);
}
string fPath = Path.Combine(directoryPath,"LastPhoto.png");
ScreenCapture.CaptureScreenshot(fPath);
Debug.Log("Screenshot created " + fPath);
return fPath;
}
It works great in the editor, but on android device i got an error that this file can not be written. What's wrong ?
<i>AndroidPlayer(ADB@127.0.0.1:34999)</i> Failed to store screen shot (/storage/emulated/0/Android/data/com.DefaultCompany.Test3D/files/storage/emulated/0/Android/data/com.DefaultCompany.Test3D/files/Screenshots/LastPhoto.png)
I can write the file with File command - same path, no problems var tex = new Texture2D(100, 100, TextureFormat.RGB24, false); var bytes = tex.EncodeToPNG(); File.WriteAllBytes(Path.Combine(directoryPath,"LastPhoto1.png"), bytes); But ScreenCapture.CaptureScreenshot doesn't work. What's up ?
Did you find something about this? I'm having the same problem with UWP.
Answer by dpkstr · May 04 at 08:45 PM
string fileName = dateTime.ToFileTime() + ".png";
#if UNITY_EDITOR
ScreenCapture.CaptureScreenshot( Application.persistentDataPath + "/" + fileName);
#else
ScreenCapture.CaptureScreenshot(fileName);
#endif
You can use this and try
Your answer
Follow this Question
Related Questions
Prevent user from copying/deleting files stored in PersistentDathPath 0 Answers
File persistence on uninstall (Application.persistentDataPath) 2 Answers
Serialize Data on iOS in persistentDataPath 0 Answers
Android PersistentDataPath UnauthorizedAccessException 0 Answers
iphone capture screen and send to server 2 Answers