System.IO.Path.GetTempFileName issue on Android

Hi,
System.IO.Path.GetTempFileName() doen’t work on Android platform, It hangs the game. Is this not supported on Android?

Thanks

No one!

I would not expect it to, but honestly haven’t tried. Mobile and console has apps sandboxed, so the idea of freely granting access to a global temp folder seems unlikely. At the same time I am not aware of a dedicated per-app temp folder standard in the android app environment.

My approach would be to store your temp files in the persistent data folder of the app (Application.persistentDataPath) or a sub folder thereof. I usually generate unique file names by using the Guid API and checking File.Exists in a little do-while loop.

Thanks for insight.
We tested on iOS and it work fine. So you right about permission level issue on Android. I am doing something inline of your suggestion, using .Net GetRandomFileName instead of Guid. And clear temp file at game start.

We discovered that this issue still persists in Android build for Unity 2017.1.p4. As a workaround we used Application.temporaryCachePath

use Guid.NewGuid().ToString() + “.png”; for temprory file name. :slight_smile:

1 Like