Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

[Errno 13] Permission denied: '/storage/emulated/0/Download android error

22 views
Skip to first unread message

Steven Gerber

unread,
Apr 16, 2025, 3:38:52 PMApr 16
to Kivy users support
So...I'm back again...this is the only platform that truly has offered assistance and I'm learning so much by going through the conversations...

I am trying to save a txt file to androids open storage areas..i.e downloads folder and no matter what I try the error keeps on popping up...

My spec file has following added...
android.permissions = android.permission.READ_EXTERNAL_STORAGE,android.permission.WRITE_EXTERNAL_STORAGE

My python code as follows...

from kivy.utils import platform
if platform == "android":
    from android.storage import primary_external_storage_path

if platform == 'android':            
            base_path =  primary_external_storage_path()
            download_dir = os.path.join(base_path, 'Download')
            if not os.path.exists(download_dir):
                os.makedirs(download_dir)
            save_path = os.path.join(download_dir, rep_name)
        else:
            base_path = os.path.dirname(os.path.abspath(__file__))
            save_path = os.path.join(base_path, rep_name)

Anyone have any ideas...There is so much info available on the net about this but thusfar, nothing I string together worked...
Thanks Steven

elli...@cox.net

unread,
Apr 16, 2025, 3:49:05 PMApr 16
to kivy-...@googlegroups.com
I have not done any work on Android, but you may find this helpful: https://github.com/Android-for-Python/Android-for-Python-Users


From: kivy-...@googlegroups.com <kivy-...@googlegroups.com> on behalf of Steven Gerber <ezs...@gmail.com>
Sent: Wednesday, April 16, 2025 12:38 PM
To: Kivy users support <kivy-...@googlegroups.com>
Subject: [kivy-users] [Errno 13] Permission denied: '/storage/emulated/0/Download android error
 
--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/kivy-users/b2b82277-b49b-4315-b739-eab53322adbdn%40googlegroups.com.

Tomek CEDRO

unread,
Apr 16, 2025, 4:28:17 PMApr 16
to kivy-...@googlegroups.com
Try files read-write in your application designated location in the
first place - that is app.user_data_dir and auto-adjusts location
according to runtime platform for you - this will confirm what you
want to do works but the location is the problem. Each Android is
different (depending on minor, major, api version, vendor, phone
model, etc etc) and they change it constantly so its a moving target
maintenance nightmare, welcome to the real world Neo :-)

https://kivy.org/doc/stable/api-kivy.app.html#kivy.app.App.user_data_dir

Another hint maybe here:

https://stackoverflow.com/questions/42466607/kivy-get-the-path-to-dcim-folder-on-any-android-device

Here is some example with code:

https://karobben.github.io/2021/03/12/Python/kivy-write2android/


I found PUDB debugger extremely helpful in Python development that
provides simple terminal ui (tui) to single step your application,
with insight to variable values, you may even execute commands in REPL
in between the lines of your code. This will make even most surprising
situations clear black on white and save you lots of time :-) I use
desktop PC to develop my application and then just cross compile it to
a mobile, so I debug on a desktop, but it should be possible to debug
directly on the mobile too (adb/ssh?) :-)

Have fun :-)
Tomek

ps/2: If you work on macOS and/or pudb output is messed up on single
stepping use `from os import environ;
environ['KIVY_LOG_MODE'] = 'MIXED'`
> --
> You received this message because you are subscribed to the Google Groups "Kivy users support" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
> To view this discussion visit https://groups.google.com/d/msgid/kivy-users/b2b82277-b49b-4315-b739-eab53322adbdn%40googlegroups.com.



--
CeDeROM, SQ7MHZ, http://www.tomek.cedro.info

Steven Gerber

unread,
Apr 17, 2025, 9:47:19 AMApr 17
to Kivy users support
Guys, thank you so much for the links...I've just spent 5 hours stringing different options together and sadly...none worked...
I found this post on your forum...
https://groups.google.com/g/kivy-users/c/sP3DPuKAaUU

and simplified it for my needs...

This worked perfectly...saving to a folder within the Documents on my Android device...
I also had to add some privileges to the spec file...

        now = datetime.now()
        dt_str = now.strftime("%d %m %Y %H-%M-%S")
        rep_name = f"ToTSlider Count - {dt_str}.txt"
        hdr = rep_name.replace(".txt","")
        for key, value in summed_values.items():
            print(f"{key}: {value}")
       
        report_content = f'"{hdr}"\n'
        for key, val in summed_values.items():
            report_content += f"{key.replace('_', ' ')}: {val}\n"

        if platform == 'android':
            from android.permissions import request_permissions, Permission
            from androidstorage4kivy import SharedStorage
            request_permissions([Permission.READ_EXTERNAL_STORAGE, Permission.WRITE_EXTERNAL_STORAGE])
            base = SharedStorage()
            base_path = base.get_cache_dir()
            temp_path = os.path.join(base_path, rep_name)
            with open(temp_path, 'w') as f:
                f.write(report_content)
            base.copy_to_shared(private_file=temp_path)

        else:
            base_path = os.path.dirname(os.path.abspath(__file__))
            save_path = os.path.join(base_path, rep_name)
            with open(save_path, 'w') as f:
                f.write(report_content)
        conn.close()

I am very sure I'll be back for more help soon lol...
Till next time...Happy Coding...Thanks for all the great work you guys do here...
I am trusting that one day, I too will be able to contribute, just as I have been blessed to do on my 2nd home..."Excel Help Forum" 
Reply all
Reply to author
Forward
0 new messages