Skip to content

Commit

Permalink
[MMCA] Add permissions external storage
Browse files Browse the repository at this point in the history
  • Loading branch information
Sobottasgithub committed Apr 29, 2024
1 parent 5292535 commit 8b18538
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/MobileCrashAnalyzer/ui/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,13 @@ def onCarouselChanged(self, *args):
def on_start(self, *args):
# Use if the os is Android to avoid Android peculiarities
if OPERATING_SYSTEM == "Android":
logger.info("Asking for permission for external storage")
self.permissions_external_storage()

context = cast('android.content.Context', mActivity.getApplicationContext())
logger.info(f"Startup application context: {context}")
intent = mActivity.getIntent()

logger.info(f"Got startup intent: {intent}")
if intent:
self.on_new_intent(intent)
Expand Down Expand Up @@ -145,8 +149,30 @@ def on_new_intent(self, intent):
J_FileUtils.copy(contentResolver.openInputStream(intent.getData()), J_FileOutputStream(cacheFile))
self.loadFile(cacheFile)
os.remove(cacheFile)
"""


# See: https://stackoverflow.com/questions/64849485/why-is-filemanager-not-working-on-android-kivymd
def permissions_external_storage(self, *args):
PythonActivity = autoclass("org.kivy.android.PythonActivity")
Environment = autoclass("android.os.Environment")
Intent = autoclass("android.content.Intent")
Settings = autoclass("android.provider.Settings")
Uri = autoclass("android.net.Uri")

if not Environment.isExternalStorageManager():
try:
activity = mActivity.getApplicationContext()
uri = Uri.parse("package:" + activity.getPackageName())
intent = Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION, uri)
currentActivity = cast("android.app.Activity", PythonActivity.mActivity)
currentActivity.startActivityForResult(intent, 101)
except Exception as e:
intent = Intent()
intent.setAction(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION)
currentActivity = cast("android.app.Activity", PythonActivity.mActivity)
currentActivity.startActivityForResult(intent, 101)

def openFile(self, *args):
logger.debug("Create file select popup dialog...")

Expand Down

0 comments on commit 8b18538

Please sign in to comment.