UnitySimpleFileBrowser
UnitySimpleFileBrowser copied to clipboard
Dn't write on android 14
Description of the bug
Assuming that all I want to file is to write a log file in a subfolder of the home or document folder, regardless of the device, thus without letting the user choose where to save, on android 14 it created a file in the place I selected but did not write the content Reproduction steps
`using SimpleFileBrowser; using System.Collections; using System.IO; using UnityEngine;
public class SaveFileExample : MonoBehaviour { private void Start() { SaveFile(); }
public void SaveFile()
{
StartCoroutine(ShowSaveDialog());
}
private IEnumerator ShowSaveDialog()
{
// open dialog
yield return FileBrowser.WaitForSaveDialog(FileBrowser.PickMode.Files, false, System.Environment.GetFolderPath(System.Environment.SpecialFolder.UserProfile), "new file.txt", "Save", "save");
//
if (FileBrowser.Success)
{
string filePath = FileBrowser.Result[0];
//
using (StreamWriter writer = new StreamWriter(filePath, false))
{
writer.Write("Content");
}
}
}
} ` Attach this to any object. The file is created but not written Platform specs
Please provide the following info if this is a Unity 3D repository.
- Unity version: 2022.3.45f1
- Platform: Android (bad works), Windows (in editor, good work)
- Device: Samsung Galaxy S8+, Android 14
- How did you download the plugin: Asset Store
Additional info impossible to catch the error
manifest:
`
You need to use FileBrowserHelpers to work with Storage Access Framework file paths on Android.
Can you share a code that shows how to do it?
Example code uses FileBrowserHelpers.CopyFile( filePath, destinationPath ); and I'd recommend the same but you can also call other functions like FileBrowserHelpers.WriteTextToFile( filePath, "Hello World" );
This time it didn't even create the file. I need to write the file in multiple times, so copying is not an applicable way.
May I see your final code?
I paste in an external file because it interprets it wrong here
https://pastebin.com/KCbWteAt
If you'll be passing raw filepaths to FileBrowserHelpers, then you can just use System.IO. It won't work though because of Android's IO restrictions. Which is why you need to use FileBrowser to pick a filepath and use that path in FileBrowserHelpers. Paths returned by FileBrowser won't be raw filepaths but rather Storage Access Framework paths.
Thanks, I don't know by what sorcery, it works, at least for now. I had come to the conclusion that android had banned writing files to external storage.
So it is not possible to export a file to a predetermined location, just asking the user for write permission only first time? Like documents/ap.2020/today.txt
I would like to ask you to add public functions to transform from an enum the standard paths, such as home, documents, sd, others, that can then be combined with subpaths
WRITE_EXTERNAL_STORAGE is removed on latest Android versions so Storage Access Framework is mandatory going forward. persistentDataPath and temporaryCachePath are safe to use, though.
There isn't a function that takes a raw filepath and converts it to Storage Access Framework path. If you find a working solution, do let me know.
OK, I was hoping that was possible. Thanks for the help. I hope someone will find a better solution.