Search Unity

Android Settings - Write Access: Internal Only vs External

Discussion in 'Android' started by TitanUnity, Aug 10, 2016.

  1. Tanek

    Tanek

    Joined:
    Apr 19, 2016
    Posts:
    45
    I am sorry @JuliusM but I don't think it is working the same way (in Unity 5.4 nor in Unity 5.5).
    As I said we are on Unity 5.5.1f1 and in production I had to implement that workaround to be able to save the game (i.e.: have a working and accessible path to save data) on some devices and avoid UnauthorizedAccessException .
    Please also note that I don't think that the issue with the "extra code" implemented in Unity 5.3 and 5.4 is related as this issue happens also on new devices (i.e.: fresh installs).
     
  2. CoopOwnz

    CoopOwnz

    Joined:
    Oct 6, 2016
    Posts:
    74
    UPDATE: I implemented the code @Tanek shared from github. I will post if I get anymore exception errors. The only piece I did not implement was the last fallback option if for whatever reason the first item in _persistentDataPath array is not writable. I didn't add this because the code already checks if the path is writable before adding it to the array so I didn't see a need for it. I want to thank @Tanek for his help in this thread. Hopefully this puts an end to this issue.
     
    Last edited: Mar 4, 2017
  3. dh151810

    dh151810

    Joined:
    Oct 11, 2015
    Posts:
    2
    Hi there,

    same problem here. I get the correct path from the code-example which @Tanek provided (thx for that), but i do have the Access Denied Exception. My device is Kindle Fire HD 8, maybe there's a similar problem like with the huawei-devices, but there is no possiblity (known to me) to change the "default storage location". Anyone any suggestions?
     
  4. GiyomuGames

    GiyomuGames

    Joined:
    Jan 12, 2015
    Posts:
    80
    I'm used Unity 5.5.2f1 for a game I just released. I set the write permission to "internal", and I see in my bug reports that some devices (Huawei LON-AL00 and WIKO SUNSET2) get an IOException when trying to save data in the persistentDataPath pointing to their external storage. They are on Android 4.4 and supposedly don't need a special permission (from what JuliusM wrote). What is going on?
     
  5. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,167
    Folks, please try using latest Unity version instead of @Tanek 's code. Should work exactly the same.
     
  6. trdinich

    trdinich

    Joined:
    Oct 5, 2016
    Posts:
    9
    @Yury-Habets sorry to revive this thread, but are you sure? I'm on Unity 5.6.2p4, and the issue that everyone is discussing in this thread still exists, and @Tanek 's solution is the only thing that I see as currently viable. Is this ever going to be fixed in Unity?
     
  7. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,167
    People have been discussing multiple issues in this thread. Please share your detailed experience to get proper feedback. At the moment, latest Unity versions should work correctly.
     
  8. BrainAndBrain

    BrainAndBrain

    Joined:
    Nov 27, 2014
    Posts:
    115
    Has anyone been able to confirm that latest Unity versions have fixed this? Would love to ship an update that allows saving on external storage.
     
  9. domdev

    domdev

    Joined:
    Feb 2, 2015
    Posts:
    375
    same problem here, any solution for this? also was using easy save 2.. its now happening on every device.. im using 5.6.2f1 unity
     
  10. smallstep

    smallstep

    Joined:
    Jan 25, 2016
    Posts:
    34
    Using Unity 2017.3 and building for Android 4.4+ :

    Can anyone confirm that when a user switches the default storage location to the SD Card via Device Settings, the app saves work as expected (even if the app has no write to external permissions)?

    Do we still need to implement @Tanek's code suggestion for a flexible persistentDataPath?
    Thanks!
     
    Bernarche likes this.
  11. RedaMakarem

    RedaMakarem

    Joined:
    Oct 21, 2012
    Posts:
    2
    Hello,
    I am using Unity 2018.1.1f1
    I am building for Android with the following Player Settings:
    Minimum API : 19
    Install Location: Prefer External
    Write Permission: External


    The directory was created on the external storage when the app is installed (/SD card/Android/data/[package-name]/files/)

    When I log Application.persistentDataPath I get the path to the internal storage (/Internal storage/Android/data/[package-name]/files/).

    I get the same result even after change the default app location to SD card

    Please let me know what to do as I am making an app that play 360 videos so internal storage is not an option

    Thanks
     
    corjn likes this.
  12. NatsupyYui

    NatsupyYui

    Joined:
    Jul 11, 2017
    Posts:
    18
    Guys, I have the same issue when trying to save a file to sdcard(external drive), saving on internal storage(primary drive) is ok, but on sdcard was denied. Using version Unity 2018.1.8f1, so any can help? @Yury-Habets
    Code (CSharp):
    1. UnauthorizedAccessException: Access to the path "/storage/84FE-1AE1/Songs/FILE-SAVING.osu" is denied.
    2. System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean anonymous, FileOptions options) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.IO/FileStream.cs:354)
    3. System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize)
    4. (wrapper remoting-invoke-with-check) System.IO.FileStream:.ctor (string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare,int)
    5.  
     
  13. AkhmedAbasov

    AkhmedAbasov

    Joined:
    Mar 13, 2014
    Posts:
    163
    Hello! My users complain about a problem with the game that arises from the recording in Application.persistentDataPath.

    Unity 2018.1.0f2 (64-bit)
    Device: Oppo CPH1859 (8.1)
    Device: OnePlus3T (OnePlus3T) (8.0)



    Code (CSharp):
    1.  
    2.             string filepath = Application.persistentDataPath + "/" + "database.db";
    3.  
    4.             if (!File.Exists(filepath))
    5.             {
    6.  
    7.                 WWW loadDB = new WWW("jar:file://" + Application.dataPath + "!/assets/" + "database.db");
    8.                 while (!loadDB.isDone) { }
    9.                 File.WriteAllBytes(filepath, loadDB.bytes);
    10.                 dbConnection = (IDbConnection)new SqliteConnection("URI=file:" + Application.persistentDataPath + "/" + "database.db");
    11.             }
    12.             else
    13.             {
    14.                 dbConnection = (IDbConnection)new SqliteConnection("URI=file:" + Application.persistentDataPath + "/" + "database.db");
    15.             }
    I was stupid when I thought that it would work everywhere.

    What is the output for the moment?