- Home /
Cant take screenshots on Android with ScreenCapture.CaptureScreenshot
It works fine on PC using Persistent data path.
ScreenCapture.CaptureScreenshot(Application.persistentDataPath + "/" + "screenshot.png");
However using that on Android doubles up on the path. And using just
ScreenCapture.CaptureScreenshot("screenshot.png");
Doesn't do anything at all.
Any suggestions? I've already checked so many forum posts but am yet to find a solution.
How do i do that? In my player settings i have - Install location - Prefer External - Write Permission - Internal. Do i need to do anything with manifest? I'm already saving data to and from the device so i can only assume i already have some permissions.
Answer by ako_unity · Aug 12, 2019 at 02:02 PM
First of all, you'll need to get all required permissions from Android OS: an access to disk storage and maybe something to be able to capture screen (this is potentially makes user vulnerable to data stealing, so should be protected somehow). Check this out.
Hi you said check this out but didn't link anything, how can i set permissions during development do i add something to manifest?
how did you check if the screenshot was saved? for adding permissions you need to upodate the manifest but i dont remember having to add anything when i once did it but was a long time ago i am not sure
This is all part of an Email/Feedback script I'm working on, so when I load the UI a screenshot is taken, then if the user selects attach screenshot it attaches the screenshot in the email. However, pressing send doesn't do anything when attach screenshot is selected, it works at sending an email without one.Everything works on PC.
public void OpenUI()
{
StartCoroutine(TakeScreenshot());
}
public IEnumerator TakeScreenshot()
{
yield return new WaitForEndOfFrame();
// if(File.Exists("feedback"))
// {
// File.Delete("feedback");
// }
// yield return new WaitForSeconds(1f);
ScreenCapture.CaptureScreenshot("feedback.png");
yield return new WaitForSeconds(.5f);
Continue();
}
public void Update()
{
chosenSubject = DropDownUI.GetComponent<T$$anonymous$$Pro.T$$anonymous$$P_Dropdown>().value;
typed$$anonymous$$essage = inputUI.GetComponent<T$$anonymous$$Pro.T$$anonymous$$P_InputField>().text;
attachScreenshot = checkboxUI.GetComponent<Toggle>().isOn;
if(attachScreenshot)
{
ToggleI$$anonymous$$G.sprite = toggleOn;
}
if(!attachScreenshot)
{
ToggleI$$anonymous$$G.sprite = toggleOff;
}
}
public void Continue()
{
Time.timeScale = 0;
FeedbackUI.SetActive(true);
}
public void SendEmails()
{
mailBody = typed$$anonymous$$essage;
if(chosenSubject == 0)
{
mailSubject = "BUG";
}
if(chosenSubject == 1)
{
mailSubject = "FEEDBAC$$anonymous$$";
}
if(chosenSubject == 2)
{
mailSubject = "OTHER";
}
mail.From = new $$anonymous$$ailAddress("E$$anonymous$$AIL");
mail.To.Add("E$$anonymous$$AIL");
if(attachScreenshot)
{
mail.Attachments.Add(new Attachment ("feedback.png"));
}
SmtpClient smtpServer = new SmtpClient("smtp.gmail.com.");
smtpServer.Port = 587;//GIVE CORRECT PORT HERE
mail.Subject = mailSubject;
mail.Body = mailBody;
smtpServer.Credentials = new System.Net.NetworkCredential("E$$anonymous$$AIL", "PASS") as ICredentialsByHost;
smtpServer.EnableSsl = true;
ServicePoint$$anonymous$$anager.ServerCertificateValidationCallback =
delegate (object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{ return true; };
smtpServer.Send(mail);
//smtpServer.SendAsync(mail)
$$anonymous$$ainBodyUI.SetActive(false);
ResultBodyUI.SetActive(true);
ResultTitle.text = "SUCCESS";
ResultBody.text = "Feedback Sent Succesfully.";
}
Your answer
Follow this Question
Related Questions
Save Image to Android Photo gallery 1 Answer
How to save screenshots on Android with Unity and C#? 0 Answers
Share Button 3 Answers
Save Screenshot and Show it in Gallery (iOS & Android) 3 Answers