Taporp Taporp - 1 year ago 277
Python Question

KIvy Android how to create and read a file

After looking all over google I haven't found a way of accessing Android internal storage from python.

I need to store an image generated by kivy app. I would like my python code to be able to navigate to a root user dir, create an app specific dir (if not found) and save the image there.

Simply creating a file with my device's path doesn't work. Should I be setting permissions for internal storage access? I'm lost with it.

Answer Source

You have something wrong in your code, you didn't paste the code nor logs, so... let's get it another way.

You can read/write with python just fine in the app folder (/data/data/org.something) with using:

app_folder = os.path.dirname(os.path.abspath(__file__))

To write to SD card you'll need to use App.user_data_dir, which as you can see in the docs on android gets you /sdcard/<app_name>. Not sure if it automatically creates it if it's missing, so it needs checking out probably. However, if it doesn't exist, just create it with python:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download