Search Unity

System.IO.Path.GetTempFileName issue on Android

Discussion in 'Scripting' started by ScareCrow99, Sep 28, 2015.

  1. ScareCrow99

    ScareCrow99

    Joined:
    Sep 8, 2015
    Posts:
    3
    Hi,
    System.IO.Path.GetTempFileName() doen't work on Android platform, It hangs the game. Is this not supported on Android?


    Thanks
     
  2. ScareCrow99

    ScareCrow99

    Joined:
    Sep 8, 2015
    Posts:
    3
    No one!
     
  3. AngryAnt

    AngryAnt

    Keyboard Operator

    Joined:
    Oct 25, 2005
    Posts:
    3,045
    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.
     
  4. ScareCrow99

    ScareCrow99

    Joined:
    Sep 8, 2015
    Posts:
    3
    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.
     
  5. juhaNEXT

    juhaNEXT

    Joined:
    Mar 11, 2016
    Posts:
    1
    We discovered that this issue still persists in Android build for Unity 2017.1.p4. As a workaround we used Application.temporaryCachePath
     
  6. PWL_Para

    PWL_Para

    Joined:
    Feb 17, 2017
    Posts:
    1
    use Guid.NewGuid().ToString() + ".png"; for temprory file name. :)
     
    breban1 likes this.