Permission to read Android storage

In my Unity game, recently it became possible to install modifications from archives directly through the game. On Windows and Linux everything works perfectly: the archive is extracted to the right path and the modifications work, to install it you just need to drag the archive to the exe of the game, or just open the file with the same exe (and similarly on Linux); and on Android to install modifications you just need to click on the archive in any file manager and select the game from the list of applications. It works. But there is one BUT: the game did not request read/write access to the internal memory, so when you open the archive just pops up a message that there is no access to the file (access denied). I will not write the details of how the error is displayed, as it is implemented in the C# code of the game through try catch. I dug through a ton of information, did almost everything I could, but the game still just does not request access to files, even in the device settings in the properties of the game in the permissions nothing. What could be the problem? Here is the code of AndroidManifest.xml:

<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="pub.SoprotivlenieBespolezno.MTS"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />

<application>
    <activity android:name="com.unity3d.player.UnityPlayerActivity" android:theme="@style/UnityThemeSelector">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.PICK" />
            <category android:name="android.intent.category.OPENABLE" />
            <data android:mimeType="*/*" />
        </intent-filter>
        <meta-data android:name="unityplayer.UnityActivity" android:value="true" />
    </activity>
</application>

Found a lot of questions on the forums, where the answer was one - “android.permission.MANAGE_EXTERNAL_STORAGE”. But it didn’t work for me. Besides the main version of Unity 2021.3.x, I tried putting newer 2022.x and 2023.x, but everywhere this problem was present. Also in Project Settings in “Write permission” I selected “External”, but that didn’t solve the problem either, although when the project was still on Unity 2019.x, it worked without changing the contents of AndroidManifest.xml…

Is there any way to solve this problem at all? Or is Unity in the latest versions poorly compatible with Android?

An app can request all-files access from the user by doing the following:

  1. Declare the MANAGE_EXTERNAL_STORAGE permission in the manifest.
  2. Use the ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION intent action to direct users to a system settings page where they can enable the following option for your app: Allow access to manage all files.

To determine whether your app has been granted the MANAGE_EXTERNAL_STORAGE permission, call Environment.isExternalStorageManager().

I tried these options, the request for access to files still did not appear, so I removed all permissions except “MANAGE_EXTERNAL_FILES”, and in the code made a request to manage all files, this request opened and players can give the game permission, but in the properties of the application still no permission to read, it must be found in a completely different section of Android settings. This worked, but for the Google Play version I had to make a separate AndroidManifest without “MANAGE_EXTERNAL_FILES” as it is forbidden. Having used Unity for so many years, I realize over the years Unity has become less and less compatible with the latest versions of the Android API.

1 Like

What was your solution for the Google Play Version without the MANAGE_EXTERNAL_FILES permission?

As a result, I disabled the functionality of modifications in the Google Play build and made in this build links to Itch, from where players can download the full version of the game without these restrictions. This turned out to be the best solution, as modifications were used by only about 15% of players, so going to the official game page and downloading the APK of the full version is not a problem for them.

1 Like