[network/kdeconnect-android] src/main: feat: Add option to toggle remote volume control using hardware volume keys
Albert Vaca Cintora <[email protected]>
| Newsgroups | gmane.comp.kde.cvs |
|---|---|
| Message-ID | <[email protected]> |
Git commit f1b35fc509daa4cfb647deecf8923a6b40b0e6fa by Albert Vaca Cintora, on behalf of Kishan Rao.
Committed on 30/07/2026 at 19:56.
Pushed by albertvaka into branch 'master'.
feat: Add option to toggle remote volume control using hardware volume keys
## Summary
This merge request provides a toggle option to enable or disable control of connected device's media volume using this phone's hardware volume buttons.
Previously, while KDE Connect was running in the background, pressing the volume buttons would trigger change in the connected device's volume, especially unknowingly.
This toggle would allow the user to choose to enable or disable this ability.
The toggle is enabled by default, ensuring backward compatibility with existing behavior.
Changes:
- Addition of a switch preference into `mprisplugin_preferences.xml`.
- Access the stored preference state, to enable or disable volume controls in `MprisMediaSession.kt`.
- Addition of appropriate strings in `strings.xml`.
## Test Plan
1. Within a connected device screen, open the `Multimedia control` tile.
1. Change the volume using hardware volume buttons, go back to the connected device screen, or the home screen of the phone.
1. On pressing the hardware volume buttons now, it will trigger volume change of the connected device.
1. Within the connected device screen, open `Plugin settings` -> `Multimedia controls`.
1, Toggle the `Hardware volume keys` switch off.
1. Repeat steps 1 - 3, it should not trigger any volume change on the connected device.
M +3 -1 src/main/java/org/kde/kdeconnect/plugins/mpris/MprisMediaSession.kt
M +3 -0 src/main/res/values/strings.xml
M +6 -0 src/main/res/xml/mprisplugin_preferences.xml
https://invent.kde.org/network/kdeconnect-android/-/commit/f1b35fc509daa4cfb647deecf8923a6b40b0e6fa
diff --git a/src/main/java/org/kde/kdeconnect/plugins/mpris/MprisMediaSession.kt b/src/main/java/org/kde/kdeconnect/plugins/mpris/MprisMediaSession.kt
index a710fcef5..a10dd096e 100644
--- a/src/main/java/org/kde/kdeconnect/plugins/mpris/MprisMediaSession.kt
+++ b/src/main/java/org/kde/kdeconnect/plugins/mpris/MprisMediaSession.kt
@@ -510,8 +510,10 @@ class MprisMediaSession : OnSharedPreferenceChangeListener, NotificationReceiver
override fun onProviderStateChanged(systemVolumeProvider: SystemVolumeProvider, isActive: Boolean) {
val mediaSession = mediaSession ?: return
+ val prefs = PreferenceManager.getDefaultSharedPreferences(context)
+ val allowVolumeKeys = prefs.getBoolean(context!!.getString(R.string.pref_mpris_volume_control_key), true)
- if (isActive) {
+ if (isActive && allowVolumeKeys) {
mediaSession.setPlaybackToRemote(systemVolumeProvider)
} else {
mediaSession.setPlaybackToLocal(AudioManager.STREAM_MUSIC)
diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml
index d506338fe..d6352641e 100644
--- a/src/main/res/values/strings.xml
+++ b/src/main/res/values/strings.xml
@@ -661,4 +661,7 @@ SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted
<string name="runcommand_output_no_output">No commands executed</string>
<string name="runcommand_stop">Stop the current command</string>
+ <string name="pref_mpris_volume_control_key" translatable="false">mpris_volume_control_enabled</string>
+ <string name="pref_mpris_volume_control_title">Hardware volume keys</string>
+ <string name="pref_mpris_volume_control_summary">Control the connected device\'s media volume using this phone\'s hardware buttons</string>
</resources>
diff --git a/src/main/res/xml/mprisplugin_preferences.xml b/src/main/res/xml/mprisplugin_preferences.xml
index 2b522f492..34cb4e678 100644
--- a/src/main/res/xml/mprisplugin_preferences.xml
+++ b/src/main/res/xml/mprisplugin_preferences.xml
@@ -35,4 +35,10 @@ SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted
android:summary="@string/mpris_keepwatching_settings_summary"
android:title="@string/mpris_keepwatching_settings_title" />
+ <SwitchPreference
+ android:id="@+id/mpris_volume_control_preference"
+ android:defaultValue="true"
+ android:key="@string/pref_mpris_volume_control_key"
+ android:summary="@string/pref_mpris_volume_control_summary"
+ android:title="@string/pref_mpris_volume_control_title" />
</PreferenceScreen>