Kxpr
Kxpr

Reputation: 23

Accessing App cache, Python for Android - Kivy

Im wondering how to view files in the directory:

/storage/emulated/0/Android/data/[app name]/cache

I am using

from android import mActivity

and

context = mActivity.getApplicationContext()
result =  context.getExternalCacheDir()
App.get_running_app().root.pathlabel.text = str(result.toString())

to collect the string and display it for reference.

Ive connected the phone to my pc, with many apps having folders in the /storage/emulated/0/Android/data/ directory, but none for my app: org.test.kivycamerafive.

Is this file hidden in some way? Or does the function return this string without the directory existing? Wondering if I can view it easily while im debugging.

Storage Permissions:

main.py:

from android.permissions import request_permissions, Permission

request_permissions([
    Permission.CAMERA,
    Permission.WRITE_EXTERNAL_STORAGE,
    Permission.READ_EXTERNAL_STORAGE
])

buildozer.spec:

android.permissions = android.permission.INTERNET,android.permission.CAMERA,android.permission.WRITE_EXTERNAL_STORAGE,android.permission.READ_EXTERNAL_STORAGE

Upvotes: 0

Views: 133

Answers (1)

Kenechukwu Akubue
Kenechukwu Akubue

Reputation: 101

Use the os.listdir to view the files in the cache directory

from android.activity import _activity as activity
from os import listdir

context = activity.getApplicationContext()
result =  context.getExternalCacheDir()

print(listdir(result.toString()))

Upvotes: 0

Related Questions