Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Storage permissions suddenly stopped working

Discussion in 'Android' started by arisdev82, Sep 14, 2020.

  1. arisdev82

    arisdev82

    Joined:
    Feb 27, 2019
    Posts:
    39
    Hi!

    I need acces to a file inside "/storage/emulated/0/.config/". It was working perfectly since last week. The permissions seem to be granted and the app ask for them. So everything seem correctly but is not working.

    I'm using Unity 2019.3.1f1 (64-bit)

    Storage path is calculated using this:

    Code (CSharp):
    1.  
    2. AndroidJavaClass jc = new AndroidJavaClass("android.os.Environment");
    3. this.storagePath = jc.CallStatic<AndroidJavaObject>("getExternalStorageDirectory").Call<string>("getAbsolutePath");
    Permissions are called using this:
    Code (CSharp):
    1.    
    2. #if PLATFORM_ANDROID
    3.             if (!Permission.HasUserAuthorizedPermission(Permission.ExternalStorageRead))
    4.             {
    5.                 Permission.RequestUserPermission(Permission.ExternalStorageRead);
    6.             }
    7.  
    8.             if (!Permission.HasUserAuthorizedPermission(Permission.ExternalStorageWrite))
    9.             {
    10.                 Permission.RequestUserPermission(Permission.ExternalStorageWrite);
    11.             }
    12. #endif
    Inside the manifest.xml
    Code (CSharp):
    1.  
    2. <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    3. <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    4.  
    and there is no line like <meta-data android:name="unityplayer.SkipPermissionsDialog" android:value="true" />

    In the editor this is the setup:

    Captura.JPG

    To read file:
    Code (CSharp):
    1.  
    2.  if (File.Exists(_path))
    3.             {
    4.                 Debug.Log("File exists: " + _path);
    5.             }
    6.             else
    7.             {
    8.                 Debug.Log("File no exists: " + _path);
    9.                 return;
    10.             }
    11.  
    12. using (StreamReader sr = new StreamReader(_path))
    13.             {
    14.                 while (!sr.EndOfStream)
    15.                 {
    16.                     string currentLine= sr.ReadLine();
    17.                     //Debug.Log("currentLine: " + currentLine);
    18.  
    19.                     this.CheckLine(currentLine, _path);
    20.                 }
    21.             }


    Any idea? Thanks in advance!
     
    Last edited: Sep 14, 2020
  2. arisdev82

    arisdev82

    Joined:
    Feb 27, 2019
    Posts:
    39