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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

READ EXTERNAL STORAGE permission not working...

Discussion in 'Android' started by danielesuppo, Oct 29, 2018.

  1. danielesuppo

    danielesuppo

    Joined:
    Oct 20, 2015
    Posts:
    331
    Hello,
    I have a script that pick all the photo in the gallery of the device. To be able to use it I have to add
    "android.permission.READ_EXTERNAL_STORAGE" to the AndroidManifest.xml.

    All work fine on my test.
    Now I've included this script in my main application, and obviously I've added the permission to the AndroidManifest.xml (in Assets\Plugins\Android folder).
    The problem is that does not work...
    in logcat I can read
    UnityEngine.AndroidJavaException: java.lang.SecurityException: Permission Denial: reading com.android.providers.media.MediaProvider uri content://media/external/images/media from pid=5167, uid=10251 requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission()

    I'm really confused because I've also examined the AndroidManifest.xml of the apk with Android Studio, and the permission is there!

    So what could be the problem?
    Many thanks for your help
     
  2. JuliusM

    JuliusM

    Unity Technologies

    Joined:
    Apr 17, 2013
    Posts:
    824
    If your device has Android 6 or newer android OS version, then just declaring the permission in the manifest is not enough. Your application must also ask for the permission to be granted during the runtime and the user of the device must grant the permission. By default Unity asks for all permissions declared in the manifest when the app is started, however if you have added
    Code (CSharp):
    1. <meta-data android:name="unityplayer.SkipPermissionsDialog" android:value="true" />
    to your manifest, then you must ask the user to grant the permission yourself.
     
  3. danielesuppo

    danielesuppo

    Joined:
    Oct 20, 2015
    Posts:
    331
    Yes, indeed I've set the value to false and now it's working.
    Thank-you!
     
  4. boubouk50

    boubouk50

    Joined:
    Jul 10, 2014
    Posts:
    15
    Hello,
    Same problem here. Whatever I tried, the dialog never pops so the permission is never granted. I have to manually turn it on to make it work.
    1. <meta-data android:name="unityplayer.SkipPermissionsDialog" android:value="false" /> is not working
    2. <uses-permission-sdk-23 android:name="android.permission.WRITE_EXTERNAL_STORAGE" tools:node="replace" /> tools is not recognized (stackoverflow solution)
    3. I'm not good enough to encapsulate Java in my code (stackoverflow solution)
    The app is deployed for API 23 and +.

    Thanks
     
  5. Voxel-Busters

    Voxel-Busters

    Joined:
    Feb 25, 2015
    Posts:
    1,834
    This is mainly because even though your plugins mention the requirement explicitly in the manifest, Unity on export will add MaxSdkVersion=18 to the final manifest file. I'm not exactly sure why unity does it in only few versions though.

    When using external photos directory we need to have it allowed in the manifest and not just limited to below API 18. Hope Unity fixes it sometime.

    Cheers,
    VB Team
     
  6. boubouk50

    boubouk50

    Joined:
    Jul 10, 2014
    Posts:
    15
    Thanks.
    Does that means I can't ask for this permission whatever I do?
    I'm not exactly sure why unity does it in only few versions though.
    Im on Unity 2018.4.5f1. Do you know what versions do not add the MaxSdkVersion?

    I found this functional solution for those who struggle with this.
     
    Last edited: Aug 8, 2019
  7. hell0425

    hell0425

    Joined:
    Oct 15, 2018
    Posts:
    9
    You can try work with Android and unity interaction。
    android studio can help you to solve this problem
    the method is useful
    ///permission==android.permission.READ_EXTERNAL_STORAGE
    public boolean CheckPeimission(String permission){
    return PermissionChecker.checkSelfPermission(this, permission)==0;
    }