From cea973175d0c6184cfda030897951cf5600c3352 Mon Sep 17 00:00:00 2001 From: matan-h Date: Mon, 11 Dec 2023 21:26:23 +0200 Subject: [PATCH 1/2] Choose a reasonable and valid number for the intent code --- plyer/platforms/android/filechooser.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plyer/platforms/android/filechooser.py b/plyer/platforms/android/filechooser.py index b8c943cf..3d144b6f 100644 --- a/plyer/platforms/android/filechooser.py +++ b/plyer/platforms/android/filechooser.py @@ -107,8 +107,8 @@ class AndroidFileChooser(FileChooser): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) - self.select_code = randint(123456, 654321) - self.save_code = randint(123456, 654321) + self.select_code = randint(100, 65536) # 65536 is the maximum. 100 to avoid conflicts. + self.save_code = randint(100, 65536) self.selection = None # bind a function for a response from filechooser activity @@ -454,7 +454,7 @@ def _resolve_uri(self, uri): elif uri_scheme == 'file': path = uri.getPath() - return path + return path or uri @staticmethod def _parse_content( From e3a740071ac3a88d1de2cae894d81b4da97ef6b7 Mon Sep 17 00:00:00 2001 From: matan-h Date: Tue, 12 Dec 2023 08:58:50 +0200 Subject: [PATCH 2/2] Add an explanation to the number choice and remove the minor change as it would require a design change --- plyer/platforms/android/filechooser.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plyer/platforms/android/filechooser.py b/plyer/platforms/android/filechooser.py index 3d144b6f..0b81e382 100644 --- a/plyer/platforms/android/filechooser.py +++ b/plyer/platforms/android/filechooser.py @@ -107,8 +107,8 @@ class AndroidFileChooser(FileChooser): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) - self.select_code = randint(100, 65536) # 65536 is the maximum. 100 to avoid conflicts. - self.save_code = randint(100, 65536) + self.select_code = randint(100, 65536-1) # 65536 is the maximum (16 bits. see https://stackoverflow.com/a/39789838/12269724). 100 to avoid possible conflicts with the system. + self.save_code = self.select_code+1 # just to avoid possible conflicts self.selection = None # bind a function for a response from filechooser activity @@ -454,7 +454,7 @@ def _resolve_uri(self, uri): elif uri_scheme == 'file': path = uri.getPath() - return path or uri + return path @staticmethod def _parse_content(