buildozer.spec
android.permissions = INTERNET,WRITE_EXTERNAL_STORAGE, READ_EXTERNAL_STORAGE
When I select an image through plyer filechooser on kivy android apk, the image path is shown correctly in the select_file.text label. But the problem is that after assigning the selected path to the image.source, the Image is not displayed.
I get this error:
03-07 09:23:11.172 23972 24300 I python : [Errno 13] Permission denied: '/storage/emulated/0/WhatsApp/Media/WhatsApp Images/IMG-20230306-WA0002.jpg'
Please help me.
# my code
from kivy.lang.builder import Builder
from
kivymd.app import MDApp
from kivy.utils import platform
from plyer import filechooser
from kivy.clock import mainthread
if platform == "android":
from android.permissions import request_permissions, Permission
request_permissions([Permission.WRITE_EXTERNAL_STORAGE, Permission.READ_EXTERNAL_STORAGE])
kv = """
MDScreen:
GridLayout:
cols:1
padding: dp(10)
spacing: dp(10)
Image:
id: image
pos_hint: {"center_x": .5, "center_y": .5}
MDLabel:
id: select_file
halign: "center"
Button:
text: "Select File"
size_hint_y: None
height: "50dp"
on_press: app.file_manager_open()
"""
class RemoveApp(MDApp):
def build(self):
return Builder.load_string(kv)
def file_manager_open(self):
fil = [("Images", ".jpg", ".jpeg", "*.png")]
filechooser.open_file(on_selection=self.handle_selection, filters=fil, multiple=True)
@mainthread
def handle_selection(self, selection):
if not selection:
return
self.root.ids.select_file.text = str(selection)
self.root.ids.image.source = selection[0]
if name == 'main':
RemoveApp().run()