Search Unity

Resolved How to get permission to external storage directory on Android?

Discussion in 'Scripting' started by blablaalb, Aug 12, 2021.

  1. blablaalb

    blablaalb

    Joined:
    Oct 28, 2015
    Posts:
    53
    The app I'm developing should be able to scan user's device for audio files. On Android 4.4 I can access folder /storage/emulated/0 without requesting any permission from the user. On a device with Android 10 I first check for permissions with
     Permission.RequestUserPermission(Permission.ExternalStorageRead) 
    and
     Permission.RequestUserPermission(Permission.ExternalStorageWrite) 
    . Both of them return true, but when I try to access /storage/emulated/0 I get the UnauthorizedAccessException.
    What am I doing wrong? Hot can I get access to the root folder and scan device for audio files?
     
  2. blablaalb

    blablaalb

    Joined:
    Oct 28, 2015
    Posts:
    53
    NVM. Based on this answer I added
     <application android:requestLegacyExternalStorage="true"> 
    . Now everything works perfect!
     
    Usin2705 and gjaccieczo like this.
  3. gjaccieczo

    gjaccieczo

    Joined:
    Jun 30, 2021
    Posts:
    306
    Thanks for the link.