Kivy permission denied on android

1,002 views
Skip to first unread message

Софья Чернышева

unread,
Feb 2, 2020, 5:04:48 PM2/2/20
to Kivy users support
Hello.
My english is bad, sorry.
I have app with FileChooser, or rather FileChooserListView.
I trying to choose the file, but getting permission denied. 
If i use path: '/data/data/org.test.myapp' in my FileChooser:
<LoadDialog>:
    title: 'load file'
    size_hint: .9, .9
    BoxLayout:
        size: root.size
        pos: root.pos
        orientation: 'vertical'
        FileChooserListView:
            id: filechooser
            path: '/data/data/org.test.myapp'
        BoxLayout:
            size_hint_y: None
            height: 30
            CommonButton:
                text: 'Cancel'
                on_release: root.dismiss()

            CommonButton:
                text: 'Load'
                on_release: root.load(filechooser.path, filechooser.selection)

i can see this directory:

p-TtwyFir3Y.jpg



But if i go "back", to parent folder, i getting:

qT1y91lh-eo.jpg


and in console abd logcat:

Screenshot_1.png


I googled and understood that it's permission problem, but i use in my buildozer.spec this code:

android.permissions = READ_EXTERNAL_STORAGE 


And in settings of my app i set permission for storage:

NG6xr1qES_o.jpg


Help please and thanks!

embryo

unread,
Feb 2, 2020, 8:33:06 PM2/2/20
to Kivy users support
Try this answer...

"In newer Android systems, the buildozer permission request for accessing the storage is not working with kivy.

To acquire these permissions you have to ask for them in your app by:

from android.permissions import request_permissions, Permission
request_permissions([Permission.WRITE_EXTERNAL_STORAGE,
                     Permission.READ_EXTERNAL_STORAGE])

... and the user will be asked to your App to access the storage.
The android library is included in the buildozer builds, so that request is all you have to do...

To get the internal storage path:

from android.storage import primary_external_storage_path
SD_CARD = primary_external_storage_path()

Note that this is the virtual (internal) SD card of the system."

Софья Чернышева

unread,
Feb 3, 2020, 12:30:18 AM2/3/20
to Kivy users support
Thanks for your answer! But how can i modify my app on PC? I have not android library, and I heard that library"android" is only on android, not on PC. If i add from android.permissions import request_permissions, Permission i getting: ModuleNotFoundError: No module named 'android', i don't know how to install it... Sorry for my stupidity =)

понедельник, 3 февраля 2020 г., 4:33:06 UTC+3 пользователь embryo написал:

Robert Flatt

unread,
Feb 3, 2020, 2:39:33 AM2/3/20
to Kivy users support
Use exception handling, for example:

try:
    # Android code
    from jnius import autoclass
    from android.runnable import run_on_ui_thread
except:
    # Desktop code
    def run_on_ui_thread(f):
        def f2(*args, **kwargs):
            pass
        return f2


Софья Чернышева

unread,
Feb 3, 2020, 12:42:36 PM2/3/20
to Kivy users support
Thank you, it's working. But still i have a problem. 
When i using:
request_permissions([Permission.WRITE_EXTERNAL_STORAGE,
                     Permission.READ_EXTERNAL_STORAGE])
it's do nothing. I don't get window with question about permission...
For check i use print and it return None in console, i think it works.

a = request_permissions([Permission.WRITE_EXTERNAL_STORAGE,
                     Permission.READ_EXTERNAL_STORAGE])

print(a)

console: 
02-03 20:32:00.273 27982 28021 I python  : None

Should this work automatically? Or should I add something else to my code? It became a problem for me..

понедельник, 3 февраля 2020 г., 10:39:33 UTC+3 пользователь Robert Flatt написал:

Robert Flatt

unread,
Feb 3, 2020, 4:28:14 PM2/3/20
to Kivy users support
request_permissions is asynchronous;  use it with a call back. The easiest way (only way?) to see is the source, close to the bottom of the file:

While investigating something else I played with this, shows working request_permissions() dialog code is in this post:
In my case this dialog approach was not the issue, as seen in the final post in that sequence

I do not know if the permissions dialog is the answer to your issue. This stuff varies by Android version and I don't understand how.

ZenCODE

unread,
Feb 5, 2020, 2:28:25 PM2/5/20
to Kivy users support
If you already have permission, the call does nothing. It only pops up the dialog box if you don't have permissions yet.

In other words, you can call it every time your app runs, but it will only popup until permissions are granted. Hope that answers your question?

Thanks

Osmar Souza

unread,
Nov 11, 2022, 3:03:31 PM11/11/22
to Kivy users support

I made an example using mdfilemanager, it works great:
Reply all
Reply to author
Forward
0 new messages