Search code examples
androidandroid-permissionsandroid-13

API 33 Android 13 non-media files not found


I am developing an app for API 33, Android 13, and non-media files are not found. According to Google, you do not need permissions to find non-media files, but these are not found, even with permissions set. Until Android 12, I got the option for "Allow management of all Files", but in Android 13, this is not possible.

When I recursively scan .bin and .png files, in Android 12 and 13, it finds both in 12, but only finds .png in 13. I do see the .bin file with the Files application in 13.

<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />

These won't work, any suggestions how to find the .bin file? I put the files on

/storage/
/sdcard/

Solution

  • It's possible to request all files permissions and then the .bin file was found on the sdcard. Tested on API 29, 31, 33.

    <uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"
            tools:ignore="ScopedStorage" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    

    MainActivity

    private void checkForExternalPermission() {
      if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.R) {
        if (!checkStoragePermission()) {
          PermissionActivity.requestStoragePermission(this, true);
        }
      } else {
        PermissionActivity.requestAllFilesAccess(this);
      }
    }
    

    PermissionActivity

    For storage permission < Android 13

    startActivity(
      new Intent(
        android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
        Uri.parse(String.format("package:%s", getPackageName()))));
    

    PermissionActivity

    For all files permissions Android 13

    Intent intent =
      new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION)
      .setData(Uri.parse("package:" + getPackageName()));
    startActivity(intent);