Hi all,
I have a strange behavior on my App that occures when I’m trying to read files from a directory.
I’m running this code to get all files in a directory. It workes fine on Windows, but gives me an error on Android
Translator.Language LoadPreferences()
{
Preferences preferences = null;
//Test
Debug.Log("UnityLog: Start Permission Check");
if (CurrentPlatform == Platform.Mobile)
{
if (Permission.HasUserAuthorizedPermission(Permission.ExternalStorageWrite) == false)
{
//Test
Debug.Log("UnityLog: Permission.ExternalStorageWrite missing");
}
if (Permission.HasUserAuthorizedPermission(Permission.ExternalStorageRead) == false)
{
//Test
Debug.Log("UnityLog: Permission.ExternalStorageRead missing");
}
}
//Test
Debug.Log("UnityLog: PersistantDataPath: " + Application.persistentDataPath);
if (Directory.Exists(Application.persistentDataPath + "/Preferences") == false)
{
Debug.Log("UnityLog: Directory Preferences existiert nicht mehr");
}
Debug.Log("UnityLog: Start Directory.GetFiles: Preferences");
string[] fileEntries = Directory.GetFiles(Application.persistentDataPath + "/Preferences/");
//Test!
if (fileEntries == null)
{
Debug.Log("UnityLog: Instanzieren von fileEntries fehlgeschlagen");
}
return null;
}
The directory is empty, but existes. I have checked it on the tablet. It is created by this code before if it would be missing:
void CheckDirectories()
{
if (Directory.Exists(Application.persistentDataPath + "/Preferences") == false)
{
Directory.CreateDirectory(Application.persistentDataPath + "/Preferences");
Debug.Log("UnityLog: Directory Preferences existiert nicht!");
}
//Test!
if (Directory.Exists(Application.persistentDataPath + "/Preferences") == false)
{
Debug.Log("UnityLog: Directory Preferences konnte nicht erstellt werden!");
}
else
{
Debug.Log("UnityLog: Directory Preferences erfolgreich erstellt!");
}
if (Directory.Exists(Application.persistentDataPath + "/Saves") == false)
{
Directory.CreateDirectory(Application.persistentDataPath + "/Saves");
}
if (Directory.Exists(Application.persistentDataPath + "/Saves/Files") == false)
{
Directory.CreateDirectory(Application.persistentDataPath + "/Saves/Files");
}
}
I added the logcat from AndroidStudio below.
Every help would be appreaciated! Sorry for some German texts in the code ^^