Screenshot is not saving to Gallery and folder

I’m taking screenshot using Application.Capturescreenshot code and it’s taking the screenshot then storing to default location. But i want to store this screenshot into one specific folder and it should display in the gallery folder also. I used below code but the screenshot is not saving to SDCard and gallery.

if (GUI.Button(new Rect(Screen.width-85,Screen.height-(Screen.height-80),80,80), Zoom_Tex,camera_icon_style)) {
				
					Screen_Shot_File_Name = model.name + System.DateTime.Now.ToString("__yyyy-MM-dd") + ".png";
					Application.CaptureScreenshot(Screen_Shot_File_Name);
					Shot_Taken = true;
					//Debug.Log("path save is "+Screen_Shot_File_Name);
					

				}
				if(Shot_Taken == true)
				{
					string Origin_Path = System.IO.Path.Combine(Application.persistentDataPath, Screen_Shot_File_Name);
					Debug.Log("Origin_Path save is "+Origin_Path);

					// This is the path of my folder.
				
					string Path = "/mnt/sdcard/DCIM/Inde/" + Screen_Shot_File_Name;
					Debug.Log("Path save is "+Path);
					if(System.IO.File.Exists(Origin_Path))
					{
						System.IO.File.Move(Origin_Path, Path);
						Debug.Log("Path_move save is "+Path);
						Shot_Taken = false;
					}
				}

Are you have a check this options Edit->Project Settings->Player->OtherSettings->WriteAccess->External Sd Card? And, if I'm not mistakes, CaptureScreenshot() save file into mnt/sdcard/android/data/"x.x.x"/files/name.png

yes..I've choosen External Sd Card

yes...the CaptureScreenshot() saving to mnt/sdcard/android/data/"x.x.x"/files/name.png...But i want to save specific folder

I've tried your code but it's not working ever the screenshot is not saving to this path also mnt/sdcard/android/data/"x.x.x"/files/name.png

Try change little path, because Application.persistentDataPath get "/data/data/com.mycompany.myapp/files". Use path as "/sdcard/DCIM/Inde". But remember, if your device have 2 or more card memory, than path is "/sdcard0/DCIM/Inde".

2 Answers

2

void captureScreenshot(string result){
if (result == “true”) {
StartCoroutine(CaptureScreen());
}
}

	void OnGUI(){
		if (GUI.Button (new Rect (20, 70, 100, 45), "Click"))
			captureScreenshot ("true");
			
		
	}
	public IEnumerator CaptureScreen()
	{
		// Wait for screen rendering to complete
		yield return new WaitForEndOfFrame();
		Application.CaptureScreenshot ("screenshot.png");

			string Origin_Path = System.IO.Path.Combine (Application.persistentDataPath, "screenshot.png");
			Debug.Log ("Origin_Path save is " + Origin_Path);

			// This is the path of my folder.
			string Path = "/mnt/sdcard/" + "screenshot.png";
			Debug.Log ("Path save is " + Path);
			if (System.IO.File.Exists (Origin_Path)) {
				System.IO.File.Move (Origin_Path, Path);
				Debug.Log ("Path_move save is " + Path);
			}
		jo.Call<bool> ("screenshotHandler", "screenshot.png");
		}

Hi Sanket, Your solution works partially. The screenshot is captured and stored at the location "Application.persistentDataPath" but "System.IO.File.Exists(Origin_Path)" returns false. So, unable to move file to sd-card at this location: "/mnt/sdcard/" . Have I missed something? and any idea why "System.IO.File.Exists(Origin_Path)" returns false whereas the file does exist. Please share your views on how to move/copy file to sd-card.

If Error: System.IO.File.Exists (Origin_Path) //returns FALSE even though file exists at Origin_Path. Please try this: public IEnumerator CaptureScreen() { Application.CaptureScreenshot ("../../../../DCIM/"+fileName); Debug.Log ("Sanky: Screen Captured"); while (!File.Exists (filePath)) { Debug.Log ("Sanky: File exist at location"+filePath); yield return 0; } /////// do whatever you want }

Camera Shot | Integration | Unity Asset Store you can use this plugin…

that is not reply stfu please