@@ -87,9 +87,13 @@ def onCarouselChanged(self, *args):
87
87
def on_start (self , * args ):
88
88
# Use if the os is Android to avoid Android peculiarities
89
89
if OPERATING_SYSTEM == "Android" :
90
+ logger .info ("Asking for permission for external storage" )
91
+ self .permissions_external_storage ()
92
+
90
93
context = cast ('android.content.Context' , mActivity .getApplicationContext ())
91
94
logger .info (f"Startup application context: { context } " )
92
95
intent = mActivity .getIntent ()
96
+
93
97
logger .info (f"Got startup intent: { intent } " )
94
98
if intent :
95
99
self .on_new_intent (intent )
@@ -145,8 +149,30 @@ def on_new_intent(self, intent):
145
149
J_FileUtils.copy(contentResolver.openInputStream(intent.getData()), J_FileOutputStream(cacheFile))
146
150
self.loadFile(cacheFile)
147
151
os.remove(cacheFile)
152
+
148
153
"""
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_APP_ALL_FILES_ACCESS_PERMISSION , uri )
168
+ currentActivity = cast ("android.app.Activity" , PythonActivity .mActivity )
169
+ currentActivity .startActivityForResult (intent , 101 )
170
+ except Exception as e :
171
+ intent = Intent ()
172
+ intent .setAction (Settings .ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION )
173
+ currentActivity = cast ("android.app.Activity" , PythonActivity .mActivity )
174
+ currentActivity .startActivityForResult (intent , 101 )
175
+
150
176
def openFile (self , * args ):
151
177
logger .debug ("Create file select popup dialog..." )
152
178
0 commit comments