Python, Kivy. После сборки APK файла через бульдозер нет доступа к файловой системе в Filechooser

После сборки APK файла через бульдозер нет доступа к файловой системе в Filechooser. В android.permissions указывал доступ на чтение и запись файлов. Если я запускаю этот код через PyDroid3, то всё работает - отображаются файлы и каталоги. Файлы проигрываются. Если запускаю собранный АПК файл - ни каталогов ни файлов. Вот мой код. После запуска приложения необходимо выбрать каталог с музыкой. В PyCharm работает тоже. Вообще это mp3 плеер с кнопкой удалить - очень мне нужная вещь. Может ещё кому-нибудь пригодится. Доп. вопрос - можно заставить filechooser отображать только каталоги?

    import kivy

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.lang import Builder
from kivy.core.audio import SoundLoader
import time
import os
import stat

selected_path = ''
sound = ''
files = []
file = 0
Builder.load_string("""
<MyWidget>:
    id: my_widget
    ScreenManager:
        id: sm

        Screen:
            name: 'screen1'
            canvas.before:
                Color:
                    rgb: .1, .1, .1
                Rectangle:
                    size: self.size
            FloatLayout:
                Button:
                    background_normal: ''
                    background_color: .1,.1,.1
                    border: (10, 10, 10, 10)
                    text: "<"
                    pos_hint: {'x': .1, 'y': .8}
                    size_hint: .2, .2
                    on_release: my_widget.press_previous()
                Button:
                    border: (10, 10, 10, 10)
                    text: "||>"
                    pos_hint: {'x': .3, 'y': .8}
                    size_hint: .2, .2
                    on_release: my_widget.press_play()
                Button:
                    text: ">"
                    pos_hint: {'x': .5, 'y': .8}
                    size_hint: .2, .2
                    on_release: my_widget.press_next()
                Button:
                    text: "[]"
                    pos_hint: {'x': .7, 'y': .8}
                    size_hint: .2, .2
                    on_release: my_widget.press_stop()                   
                Button:
                    text: "X"
                    pos_hint: {'x': .7, 'y': .2}
                    size_hint: .2, .2
                    on_release: my_widget.press_x()
                Button:
                    size_hint: .2, .2
                    text: 'Настройки'
                    pos_hint: {'x': .5, 'y': .6}
                    on_release: sm.current = 'screen2'
                    
        Screen:
            name: 'screen2'
            canvas.before:
                Color:
                    rgb: .8, .2, .2
                Rectangle:
                    size: self.size
            BoxLayout:
                orientation: 'vertical'
                col: 2
                FileChooserListView:
                    id: filechooser
                    on_selection: my_widget.selected(filechooser.selection)
                Label:
                    text: filechooser.path
                FloatLayout:
                    Button:
                        size_hint: .2, .2
                        pos_hint: {'x': .6, 'y': .2}
                        text: "Выбрать"
                        on_release:
                            sm.current = 'screen1'
                            my_widget.open(filechooser.path, filechooser.selection)
                    Button:
                        size_hint: .2, .2
                        pos_hint: {'x': .2, 'y': .2}
                        text: 'Обратно'
                        on_release: sm.current = 'screen1'
        
""")

class MyWidget(BoxLayout):
    def open(self, path, filename):
        global files
        global selected_path
        time.sleep(1)
        selected_path = path
        files = [x[0]+ '//' + f for x in os.walk(selected_path) for f in x[2] if f.endswith(".mp3")]
        print (path)
        print (files)

    def selected(self, filename):
        print ("selected: %s" % filename[0])

    def play_on():
        global sound
        global file
        global files
        sound = SoundLoader.load(files[file])
        if sound:
            print("Sound found at %s" % sound.source)
            print("Sound is %.3f seconds" % sound.length)
            sound.play()
            
    def press_play(self):
        MyWidget.play_on() 

    def press_stop(self):
        global sound
        if sound:
            sound.stop()
            
    def press_previous(self):
        global file
        global files
        MyWidget.press_stop(self)
        if file == 0:
            file = len(files) - 1
            MyWidget.play_on()
        else:
            file -= 1
            MyWidget.play_on()
            
    def press_next(self):
        global file
        global files
        MyWidget.press_stop(self)
        if file == len(files) - 1:
            file = 0
            MyWidget.play_on()
        else:
            file += 1
            MyWidget.play_on()
            
    def press_x(self):
        global files
        global file
        global selected_path
        MyWidget.press_stop(self)
        os.chmod(files[file], stat.S_IWRITE)
        os.remove(os.path.normpath(files[file]))
        f = files.pop(file)
        print(f)
        MyWidget.play_on()


class MyApp(App):
    def build(self):
        return MyWidget()


if __name__ == '__main__':
    MyApp().run()


 

Ответы (0 шт):