ScreenCapture.CaptureScreenshot doesn't work

Hi, I am trying to take a screen shot within magic leap. By debugging, I am sure that I have already reach the line of ScreenCapture.CaptureScreenshot(filePath), and the folder was created. However, after execution of the app, there was no picture saved in the folder. Here is the code:

        public void CaptureAndSaveScreenshot() {
            DebugText.text = "Start Coroutine";
            StartCoroutine(CaptureScreenshotCoroutine());
        }

        private IEnumerator CaptureScreenshotCoroutine() {
            yield return new WaitForEndOfFrame();
            string filePath = GetScreenshotPathWithTimestamp();
            string directory = Path.GetDirectoryName(filePath);
            if (!Directory.Exists(directory)) {
                Directory.CreateDirectory(directory);
            }
            DebugText.text = "before screenshot";
            ScreenCapture.CaptureScreenshot(filePath);
            DebugText.text = "finish";
        }

        private string GetScreenshotPathWithTimestamp() {
            string dateTimeFormat = System.DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss");
            string filename = dateTimeFormat + ".png";

            #if UNITY_EDITOR
            string folderPath = Path.Combine(Application.dataPath, "Screenshots");
            #elif UNITY_ANDROID || UNITY_IOS
            string folderPath = Path.Combine(Application.persistentDataPath, "Screenshots");
            #else
            string folderPath = Path.Combine(Application.dataPath, "Screenshots");
            #endif

            return Path.Combine(folderPath, filename);
        }

The CaptureAndSaveScreenshot() is called in update when I triggered the controller. Any hints/idea about why it doesn't is highly appreciate.

I recommend adding additional debug statements, then checking the logs to see if the script completes successfully by reading the logs. You should also check if you are running into any errors.

DebugText.text = "before screenshot";
DebugText.text = "finish";

These lines in my code are for debug printing. They both printed out.
Is that sufficient to prove the ScreenCapture.CaptureScreenshot(filePath); is already called successfully? Meanwhile, I also used debug print to check and show that the filePath is exist.

For the log, do you mean by the log in Device bridge?

Printing out the file location might help you locate where is it being saved on device. Additionally, you can capture the logs via ADB or device bridge through the Magic Leap Hub. You can also use the Unity ADB log cat package.