From ce640bb1f3030f4c710a5ba435d463357928b6bd Mon Sep 17 00:00:00 2001 From: gyro Date: Wed, 24 Jan 2024 19:08:12 -0800 Subject: [PATCH] Move request for microphone permission to onCreate This request can cause issues if the user denies the microphone permission. Calling requestPermissions causes GrantPermissionsActivity to be launched. Citra's MainActivity will pause. GrantPermissionsActivity will immediately finish as the user has already denied the permission. Citra's MainActivity then gets resumed and then tries to request the permission again forming a loop. --- .../java/org/citra/citra_emu/ui/main/MainActivity.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/android/app/src/main/java/org/citra/citra_emu/ui/main/MainActivity.java b/src/android/app/src/main/java/org/citra/citra_emu/ui/main/MainActivity.java index 2f14fb554..e959163d2 100644 --- a/src/android/app/src/main/java/org/citra/citra_emu/ui/main/MainActivity.java +++ b/src/android/app/src/main/java/org/citra/citra_emu/ui/main/MainActivity.java @@ -184,6 +184,10 @@ protected void onCreate(Bundle savedInstanceState) { requestNotificationPermissionLauncher.launch(Manifest.permission.POST_NOTIFICATIONS); } } + if (ContextCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) { + // Request permission if it's not granted + ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.RECORD_AUDIO}, 0); + } // Check for the TWO_INSTANCES string extra if (getIntent().getBooleanExtra(VrActivity.EXTRA_ERROR_TWO_INSTANCES, false)) { Log.error("Error: two instances of CitraVr::VrActivity were running at the same time!"); @@ -214,10 +218,6 @@ protected void onSaveInstanceState(@NonNull Bundle outState) { @Override protected void onResume() { super.onResume(); - if (ContextCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) { - // Request permission if it's not granted - ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.RECORD_AUDIO}, 0); - } mPresenter.addDirIfNeeded(new AddDirectoryHelper(this)); ThemeUtil.setSystemBarMode(this, ThemeUtil.getIsLightMode(getResources()));