Tuesday, December 7, 2021
HomeiOS Developmentios - load pictures from Images.app into Kivy app

ios – load pictures from Images.app into Kivy app


I would like to load a photo from a photos.app into my Kivy application.

I am using MDFileManager from KivyMD. It works fine on my computer, but when installed on a tablet, the folders I see are empty.

enter image description here

I've tried to pass a path to the photos.app (self.file_manager.show('/var/mobile/Media/DCIM/')), but it's also empty.

I also added Privacy - Photo Library Usage Description(value: $(PRODUCT_NAME) photo use) to Info.plist file.

Do I need some kind of permissions to access the photos?

class SecondScreen(Screen):

    def __init__(self,**kwargs):
        super(SecondScreen, self).__init__(**kwargs)

        Window.bind(on_keyboard=self.events)
        self.manager_open = False
        self.file_manager = MDFileManager(
            exit_manager=self.exit_manager,
            select_path=self.select_path,
            preview=True,
        )

    def file_manager_open(self):
        self.file_manager.show('/var/mobile/Media/DCIM/')  ### it's empty..
        self.file_manager.show("https://stackoverflow.com/")
        self.manager_open = True

    def select_path(self, path):
        self.path = path
        self.exit_manager()

        # load the image
        self.load_image()

    def exit_manager(self, *args):
        self.manager_open = False
        self.file_manager.close()

    def events(self, instance, keyboard, keycode, text, modifiers):
        '''Called when buttons are pressed on the mobile device.'''
        if keyboard in (1001, 27):
            if self.manager_open:
                self.file_manager.back()
        return True

    def load_image(self):

        try:
            # load the image
            self.pil_image = PIL_Image.open(self.path) 

            # set flag
            self.imageTakenFlag  = 1

        except:
            toast('Is not an image...')

        return self.pil_image, self.imageTakenFlag



Thanks in advance!
Best,
Dawid

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments