From 9d96fe56f241e03728ec4fffde9b58ddc50f0ee5 Mon Sep 17 00:00:00 2001 From: Dexer <73297572+DexerBR@users.noreply.github.com> Date: Wed, 1 Nov 2023 13:47:56 -0300 Subject: [PATCH] fix _get_sdcard_dir for Android API < 24 (#781) --- plyer/platforms/android/storagepath.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/plyer/platforms/android/storagepath.py b/plyer/platforms/android/storagepath.py index a2b4c102..d18ea614 100755 --- a/plyer/platforms/android/storagepath.py +++ b/plyer/platforms/android/storagepath.py @@ -4,6 +4,7 @@ ''' from plyer.facades import StoragePath +from plyer.platforms.android import SDK_INT from jnius import autoclass, cast from android import mActivity @@ -31,14 +32,20 @@ def _get_sdcard_dir(self): ) if storage_manager is not None: - storage_volumes = storage_manager.getStorageVolumes() - for storage_volume in storage_volumes: - if storage_volume.isRemovable(): - try: - directory = storage_volume.getDirectory() - except AttributeError: - directory = storage_volume.getPathFile() - path = directory.getAbsolutePath() + if SDK_INT >= 24: + storage_volumes = storage_manager.getStorageVolumes() + for storage_volume in storage_volumes: + if storage_volume.isRemovable(): + try: + directory = storage_volume.getDirectory() + except AttributeError: + directory = storage_volume.getPathFile() + path = directory.getAbsolutePath() + else: + storage_volumes = storage_manager.getVolumeList() + for storage_volume in storage_volumes: + if storage_volume.isRemovable(): + path = storage_volume.getPath() return path