From 53b4310804e874226b646f908d74fbd6493a1536 Mon Sep 17 00:00:00 2001 From: alexytomi <60690056+alexytomi@users.noreply.github.com> Date: Tue, 2 Sep 2025 00:27:41 +0800 Subject: [PATCH] feat(settings): Add microphone permission prompt --- .../net/kdt/pojavlaunch/LauncherActivity.java | 24 +++++++++++++++++++ .../screens/LauncherPreferenceFragment.java | 6 +++++ .../src/main/res/values/strings.xml | 2 ++ .../src/main/res/xml/pref_main.xml | 5 ++++ 4 files changed, 37 insertions(+) diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/LauncherActivity.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/LauncherActivity.java index a3c296523..8498e93fb 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/LauncherActivity.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/LauncherActivity.java @@ -166,7 +166,9 @@ public class LauncherActivity extends BaseActivity { }; private ActivityResultLauncher mRequestNotificationPermissionLauncher; + private ActivityResultLauncher mRequestMicrophonePermissionLauncher; private WeakReference mRequestNotificationPermissionRunnable; + private WeakReference mRequestMicrophonePermissionRunnable; @Override protected boolean shouldIgnoreNotch() { @@ -206,6 +208,16 @@ public class LauncherActivity extends BaseActivity { } } ); + mRequestMicrophonePermissionLauncher = registerForActivityResult( + new ActivityResultContracts.RequestPermission(), + isAllowed -> { + if(!isAllowed) handleNoNotificationPermission(); + else { + Runnable runnable = Tools.getWeakReference(mRequestMicrophonePermissionRunnable); + if(runnable != null) runnable.run(); + } + } + ); getWindow().setBackgroundDrawable(null); bindViews(); checkNotificationPermission(); @@ -343,6 +355,11 @@ public class LauncherActivity extends BaseActivity { this, Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_DENIED; } + public boolean checkForMicrophonePermission() { + return ContextCompat.checkSelfPermission( + this, + Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_DENIED; + } public void askForNotificationPermission(Runnable onSuccessRunnable) { if(Build.VERSION.SDK_INT < 33) return; @@ -352,6 +369,13 @@ public class LauncherActivity extends BaseActivity { mRequestNotificationPermissionLauncher.launch(Manifest.permission.POST_NOTIFICATIONS); } + public void askForMicrophonePermission(Runnable onSuccessRunnable) { + if(onSuccessRunnable != null) { + mRequestMicrophonePermissionRunnable = new WeakReference<>(onSuccessRunnable); + } + mRequestMicrophonePermissionLauncher.launch(Manifest.permission.RECORD_AUDIO); + } + /** Stuff all the view boilerplate here */ private void bindViews(){ mFragmentView = findViewById(R.id.container_fragment); diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/screens/LauncherPreferenceFragment.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/screens/LauncherPreferenceFragment.java index 7275f8691..d4791a6f1 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/screens/LauncherPreferenceFragment.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/screens/LauncherPreferenceFragment.java @@ -35,6 +35,7 @@ public class LauncherPreferenceFragment extends PreferenceFragmentCompat impleme private void setupNotificationRequestPreference() { Preference mRequestNotificationPermissionPreference = requirePreference("notification_permission_request"); + Preference mMicrophonePermissionPreference = requirePreference("microphone_permission_request"); Activity activity = getActivity(); if(activity instanceof LauncherActivity) { LauncherActivity launcherActivity = (LauncherActivity)activity; @@ -43,6 +44,11 @@ public class LauncherPreferenceFragment extends PreferenceFragmentCompat impleme launcherActivity.askForNotificationPermission(()->mRequestNotificationPermissionPreference.setVisible(false)); return true; }); + mMicrophonePermissionPreference.setVisible(!launcherActivity.checkForMicrophonePermission()); + mMicrophonePermissionPreference.setOnPreferenceClickListener(preference -> { + launcherActivity.askForMicrophonePermission(()->mMicrophonePermissionPreference.setVisible(false)); + return true; + }); }else{ mRequestNotificationPermissionPreference.setVisible(false); } diff --git a/app_pojavlauncher/src/main/res/values/strings.xml b/app_pojavlauncher/src/main/res/values/strings.xml index 15ff64e01..cfa000bde 100644 --- a/app_pojavlauncher/src/main/res/values/strings.xml +++ b/app_pojavlauncher/src/main/res/values/strings.xml @@ -472,4 +472,6 @@ TouchController vibrate length Set the length of the vibration when using TouchController. Vanilla json seems to be corrupt. Please send a bug report on github or discord. + Allow microphone + Click to re-request the notification permission, required for voice chat mods like Simple Voice Chat. diff --git a/app_pojavlauncher/src/main/res/xml/pref_main.xml b/app_pojavlauncher/src/main/res/xml/pref_main.xml index d7df2d92f..402e22abf 100644 --- a/app_pojavlauncher/src/main/res/xml/pref_main.xml +++ b/app_pojavlauncher/src/main/res/xml/pref_main.xml @@ -66,6 +66,11 @@ android:summary="@string/preference_ask_for_notification_description" android:key="notification_permission_request" /> +