Search Unity

IO exceptions while saving screen shot in android devices

Discussion in 'Scripting' started by Naveed_Khurshid, Mar 19, 2019.

  1. Naveed_Khurshid

    Naveed_Khurshid

    Joined:
    Oct 8, 2016
    Posts:
    4
    I am getting these exception while saving screenshot in android devices.

    IOException: Disk full. Path /storage/emulated/0/Android/data/com.ksg.kite.flight.apps/SavedScree..

    Managed Stack Trace:

    System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean anonymous, FileOptions options)
    System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize)
    System.IO.File.Create (System.String path, Int32 bufferSize)
    System.IO.File.Create (System.String path)
    System.IO.File.WriteAllBytes (System.String path, System.Byte[] bytes)
    MyShare+<CapturingSS>c__Iterator0.MoveNext ()
    UnityEngine.SetupCoroutine.InvokeMoveNext (IEnumerator enumerator, IntPtr returnValueAddress)


    IOException: Too many open files
    Managed Stack Trace:

    System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean anonymous, FileOptions options)
    System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize)
    System.IO.File.Create (System.String path, Int32 bufferSize)
    System.IO.File.Create (System.String path)
    System.IO.File.WriteAllBytes (System.String path, System.Byte[] bytes)
    MyShare+<CapturingSS>c__Iterator0.MoveNext ()
    UnityEngine.SetupCoroutine.InvokeMoveNext (IEnumerator enumerator, IntPtr returnValueAddress)


    UnauthorizedAccessException: Access to the path "/storage/emulated/0/Android/data/

    Managed Stack Trace:

    System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean anonymous, FileOptions options)
    System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize)
    System.IO.File.Create (System.String path, Int32 bufferSize)
    System.IO.File.Create (System.String path)
    System.IO.File.WriteAllBytes (System.String path, System.Byte[] bytes)
    MyShare+<CapturingSS>c__Iterator0.MoveNext ()
    UnityEngine.SetupCoroutine.InvokeMoveNext (IEnumerator enumerator, IntPtr returnValueAddress)




    Code (CSharp):
    1. string filePath;
    2.  
    3. Texture2D ss = new Texture2D( Screen.width, Screen.height, TextureFormat.RGB24, false );
    4.         ss.ReadPixels( new Rect( 0, 0, Screen.width, Screen.height ), 0, 0 );
    5.         ss.Apply();
    6.  
    7.  
    8.         filePath = Application.persistentDataPath + "/../SavedScreen.png";
    9.  
    10.         File.WriteAllBytes( filePath, ss.EncodeToPNG() );

    In player settings write permission is set to internal.
    Your feedback is highly appreciated.