Help with access/write files on Android

hi everybody,
I’m trying to write a file to the Application.dataPath and to the sdcard but both of it doesn’t work.
I’ve been searching for quite a while now, but it seems that this topic is not really well covered yet.
To do this I slightly modified this script from the Scripting Reference:

// Saves screenshot as PNG file.
import System.IO;

// Take a shot immediately
function OnGUI () {
	if (GUI.Button (Rect (10,10,150,100), "write")) {
		print ("You clicked the button!");
		UploadPNG ();
	}
}

function UploadPNG () {
    // We should only read the screen bufferafter rendering is complete
    yield WaitForEndOfFrame();
    
    // Create a texture the size of the screen, RGB24 format
    var width = Screen.width;
    var height = Screen.height;
    var tex = new Texture2D (width, height, TextureFormat.RGB24, false);
    // Read screen contents into the texture
    tex.ReadPixels (Rect(0, 0, width, height), 0, 0);
    tex.Apply ();

    // Encode texture into PNG
    var bytes = tex.EncodeToPNG();
    Destroy (tex);

    // For testing purposes, also write to a file in the project folder
    //File.WriteAllBytes(Application.dataPath + "/SavedScreen.png", bytes);
    File.WriteAllBytes("/sdcard/testfolder/testWrite.png", bytes);
    
}

When I press tho button nothing happens and in the LogCat I get the following messages:

  • for saving to sdcard:

-for saving to Application.dataPath:

My scripting skills are very basic so maybe I do something completely wrong, but I need to figure this out.
Please help me!
Thanks a lot,

Stefan

Did you try posting in the Android sector of the forum they may know over there.

Not so far, thanks for the idea…
I’ll post it there.