@@ -87,9 +87,13 @@ def onCarouselChanged(self, *args):
8787 def on_start (self , * args ):
8888 # Use if the os is Android to avoid Android peculiarities
8989 if OPERATING_SYSTEM == "Android" :
90+ logger .info ("Asking for permission for external storage" )
91+ self .permissions_external_storage ()
92+
9093 context = cast ('android.content.Context' , mActivity .getApplicationContext ())
9194 logger .info (f"Startup application context: { context } " )
9295 intent = mActivity .getIntent ()
96+
9397 logger .info (f"Got startup intent: { intent } " )
9498 if intent :
9599 self .on_new_intent (intent )
@@ -145,8 +149,27 @@ def on_new_intent(self, intent):
145149 J_FileUtils.copy(contentResolver.openInputStream(intent.getData()), J_FileOutputStream(cacheFile))
146150 self.loadFile(cacheFile)
147151 os.remove(cacheFile)
152+
148153 """
149-
154+
155+ # See: https://stackoverflow.com/questions/64849485/why-is-filemanager-not-working-on-android-kivymd
156+ def permissions_external_storage (self , * args ):
157+ PythonActivity = autoclass ("org.kivy.android.PythonActivity" )
158+ Environment = autoclass ("android.os.Environment" )
159+ Intent = autoclass ("android.content.Intent" )
160+ Settings = autoclass ("android.provider.Settings" )
161+ Uri = autoclass ("android.net.Uri" )
162+
163+ if not Environment .isExternalStorageManager ():
164+ try :
165+ activity = mActivity .getApplicationContext ()
166+ uri = Uri .parse ("package:" + activity .getPackageName ())
167+ intent = Intent (Settings .ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION , uri )
168+ currentActivity = cast ("android.app.Activity" , PythonActivity .mActivity )
169+ currentActivity .startActivityForResult (intent , 101 )
170+ except Exception as e :
171+ self .createPopup ("Something went wrong! Please try again! \n %s" % e )
172+
150173 def openFile (self , * args ):
151174 logger .debug ("Create file select popup dialog..." )
152175
0 commit comments