Search Unity

What exactly causes Unity to make an app ask "access to photo, media, and files on this device"?

Discussion in 'Android' started by Steven-1, Dec 27, 2017.

  1. Steven-1

    Steven-1

    Joined:
    Sep 11, 2010
    Posts:
    471
    I know Unity adds permissions based on what classes I use and such (https://docs.unity3d.com/Manual/android-manifest.html), and I found some info on how to modify the manifest file, to alter permissions,

    but I'm wondering why Unity added the files access permission in the first place, when I don't have any code that needs this.

    Because you don't need the files access permission to save and load playerprefs, right? (Or am I mistaken?)

    Unity added it when I wrote some AR test code, but after I removed all of it, the permission remained.

    Anyone knows why the permission is still there?
    (and a clean way to make it go away?)
     
  2. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    What is the permission name, and how are you checking permissions? Using aapt perhaps? Googling for this issue points to assets that don't have a minSdkVersion set, which apparently triggers the permission requirements.
     
  3. TheHighGround

    TheHighGround

    Joined:
    Nov 19, 2017
    Posts:
    68
    If controlling the permissions is such a big deal just override the Manifest unity generates. You can find it in Temp/StagingArea/AndroidManifest.xml copy that to Assets/Plugins/Android and remove the permissions and build.
     
  4. Steven-1

    Steven-1

    Joined:
    Sep 11, 2010
    Posts:
    471
    I don't know what the name is and don't check permissions (I've no idea what aapt is).

    I'm fairly new to developing for android, so I don't know much about all of this.

    The app just asks: "Allow app to access photo, media, and files on this device?", which I believe is because of a permission. (that is correct right?)

    About that minSdkVersion, is that the minimum api level in the PlayerSettings? (I'm guessing that because of this: https://docs.unity3d.com/ScriptReference/PlayerSettings.Android-minSdkVersion.html)
    It's set to Anroid 4.1 (which is the default I believe, I know I didn't change it anyway)
     
  5. Steven-1

    Steven-1

    Joined:
    Sep 11, 2010
    Posts:
    471
    It's not that it's a big deal, it's just that it shouldn't be there in the first place I think.
    Also, there's no StagingArea folder in the Temp folder, and the manifest file I find elsewhere in the project doesn't contain any permissions.
    (And the one in the build file is unreadable)

    I read that you supposedly can remove permissions in the manifest by exporting the project to android studio, but like I said, if I can you just prevent Unity from adding the permission it would be better I think.
     
  6. Steven-1

    Steven-1

    Joined:
    Sep 11, 2010
    Posts:
    471
    I'll rephrase my question:
    What exactly causes Unity to add the permission that makes an app ask "access to photo, media, and files on this device?".
    (including certain classes, certain player settings, ...?)
     
  7. TheHighGround

    TheHighGround

    Joined:
    Nov 19, 2017
    Posts:
    68
    Unity scans your code and if it sees you are requesting permissions it itself is aware of like say Input.location it will add the permission automatically when it generates the AndroidManifest.xml file.
     
  8. Steven-1

    Steven-1

    Joined:
    Sep 11, 2010
    Posts:
    471
    Yes I know, that's what I said. But what exactly makes it add this specific permission that makes the app ask "access to photo, media, and files on this device"?
     
  9. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,205
    Assets from the store may require permissions depending on how they work and the API level you've specified. Just as an example GameAnalytics stores a database while the user is offline and depending on the API level uses a different location to store it that may conflict with permissions.

    https://github.com/GameAnalytics/GA-SDK-UNITY/wiki/Android-Build
     
  10. Steven-1

    Steven-1

    Joined:
    Sep 11, 2010
    Posts:
    471
    I don't use that. The only plugin I use is one for the google play game services, but I already had this permission issue before I ever used that.
     
  11. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,205
    You mentioned writing some AR test code. Did you use any assets for the brief period you were working with it?
     
  12. Steven-1

    Steven-1

    Joined:
    Sep 11, 2010
    Posts:
    471
    No it was purely my own code
     
  13. panzerkoblyk

    panzerkoblyk

    Joined:
    May 1, 2017
    Posts:
    13
    IgorAherne likes this.
  14. JuliusM

    JuliusM

    Unity Technologies

    Joined:
    Apr 17, 2013
    Posts:
    836
    As panzerkoblyk has said, READ_EXTERNAL_STORAGE permission is added if you are splitting application binary. This permission is also added if you make a development build, if you have cardboard VR enabled or if there is a custom manifest that does not have minSdkVersion and targetSdkVersion set (as was mentioned by JeffDUnity3D). Note that the custom manifest could be inside a plugin. If the manifest does not have minSdkVersion and targetSdkVersion set, they are assumed to be set to 1, which according to android docs https://developer.android.com/reference/android/Manifest.permission.html#READ_EXTERNAL_STORAGE adds the permission.
     
    marvpaul, IgorAherne and markachten88 like this.
  15. Steven-1

    Steven-1

    Joined:
    Sep 11, 2010
    Posts:
    471
    I've never heard of that, and the option in the publishing settings is off.
    It's not a development build, it's not VR, and as I said, I've had this problem from before using a plugin, and didn't use any custom manifest file before using the plugin.
    I checked the plugin, and it contains 2 manifest files, both without permission stuff in it, but one of them has:
    Code (CSharp):
    1. <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="16" />
    and the other:
    Code (CSharp):
    1. <uses-sdk android:minSdkVersion="14" />
    I dunno if that can cause it?

    Otherwise, is there any using statement that can cause this permission to be added?
    Or does using PlayerPrefs cause this permission? (I was told it doesn't, but you never know)
     
  16. RationeUtor

    RationeUtor

    Joined:
    Apr 25, 2015
    Posts:
    7
    Check if you have Write Permission set to "External (SDCard) within Player Settings. If yes, that's why you are seeing the app asking for access to photo, media, and files on the device.
     
  17. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,167
    Likely. The second one should have targetSdkVersion as well.
     
  18. domdev

    domdev

    Joined:
    Feb 2, 2015
    Posts:
    375
    I had this issue too in cloud build?any solution? it not showing when I build it locally
     
  19. javedphonato

    javedphonato

    Joined:
    Mar 5, 2018
    Posts:
    1
    Prompting your user to allow dangerous permissions is the only way to ensure plug-ins don’t cause crashes when they are missing a permission. However, if you don’t want your Unity Android app to ask for permissions on startup, you can add the following to your Manifest in either the Application or Activity sections.

    <meta-data android:name="unityplayer.SkipPermissionsDialog" android:value="true" />
     
    IgorAherne likes this.
  20. gurmeetsh98

    gurmeetsh98

    Joined:
    Dec 26, 2019
    Posts:
    3
    Also check if
    Player Settings--->Other Settings-->Write Permission-->External(SDCard)
    is enabled this asks for that permission.
    turn to internal if not saving anything on sd card or storage outside you apps internal
     
  21. honor0102

    honor0102

    Joined:
    Jan 30, 2019
    Posts:
    26
    For those who need to figure it out
    i had a similar problem
    to find what is causing to add unwanted permission to my project i checked a file in temporary files of unity project named "manifest-merger-release-report.txt"
    its path depends of your unity version but probably you wil find it somewhere in project,probably in one of these :

    path\to\my\project\Temp\gradleOut\launcher\build\outputs\logs\manifest-merger-release-report.txt
    or
    path/to/my/project/Temp/gradleOut/build/outputs/logs/manifest-merger-release-report.txt
    or
    path/to/my/project/Library/Bee/Android/Prj/IL2CPP/Gradle/launcher/build/outputs/logs/manifest-merger-release-report.txt

    search in it for permission name like "EXTERNAL_STORAGE" and trace what caused to add it
    i found this soloution here:
    https://stackoverflow.com/questions/40931058/how-to-find-source-of-a-permission-in-unity-android
    also if you want to remove an unwanted permision,try using this method in android manifest(before application tag) to ignore a permision that was automatically added to project by a plugin:
     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" tools:node="remove" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" tools:node="remove" />


    these worked for me,in my case admob plugin had a bug for that,and this method fixed it,hope it helps!
     
    Last edited: May 9, 2023
    marvpaul likes this.