dynamically create a folder in kivy and python on androind

263 views
Skip to first unread message

manohisoa guy aimar

unread,
Nov 21, 2020, 12:40:36 PM11/21/20
to Kivy users support
I'm sorry because I ask questions all the time
 I have solved the last liver problem.

Now I have a question, is it possible to create a folder dynamically in the storage of my android with my App? In kivymd and python3.

Because I have already tried but on the computer, it works very well but on my android, the application does not even launch

Here is my test:


def rep(self):
        dos=os.getenv('/') if platform == 'android' else os.path.expanduser("~")
        dos1=dos+"/WanOffice"
        try:
             os.makedirs(dos1)
        except OSError:
            if not os.path.isdir(dos1):
                Raise

If anyone has an idea, I thank them already

Andreas Ecker

unread,
Nov 21, 2020, 2:25:37 PM11/21/20
to kivy-...@googlegroups.com
to get your test working replace the `os.getenv('/')` expression with "." (a string with a single dot character which refers to your (hidden) app installation folder).

Android is much more restrictive on user rights than your computer's OS (assuming linux). On Android your app has only full rights to create a folder within the app folder.

For to create a new folder in the public storage of your android phone (in the memory or on the sdcard) you need to request special permissions (for more info search for WRITE_EXTERNAL_STORAGE and requestPermissions).


--
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 on the web visit https://groups.google.com/d/msgid/kivy-users/21583737-041f-43ae-8099-a068508bb10bn%40googlegroups.com.

planckp...@gmail.com

unread,
Nov 21, 2020, 3:09:14 PM11/21/20
to Kivy users support
Here is a runable example of lots of ways to access the 3 folders you can reliably access on Android

There are two different types of permissions (Manifest and App), the need for them varies depending on Android version and directory. Safest just to always include them.
main.py

manohisoa guy aimar

unread,
Nov 22, 2020, 1:53:21 AM11/22/20
to kivy-...@googlegroups.com
Hello

Thank you very much it works really well.

You are genius

Le sam. 21 nov. 2020 à 23:09, planckp...@gmail.com
<planckp...@gmail.com> a écrit :
> To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/f0ea1712-0a3d-449c-86cb-6ce4ef725984n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages