@@ -3,6 +3,7 @@ package org.wordpress.android.ui.prefs.language
3
3
import android.content.Context
4
4
import android.content.Intent
5
5
import android.net.Uri
6
+ import android.os.Build
6
7
import android.provider.Settings
7
8
import androidx.appcompat.app.AppCompatDelegate
8
9
import androidx.core.os.LocaleListCompat
@@ -85,18 +86,25 @@ class LocaleHelper @Inject constructor(
85
86
}
86
87
87
88
/* *
88
- * Open the app settings screen so the user can change the app locale - note that
89
- * the locale is only available in API 33+
89
+ * Open the app settings screen so the user can change the app language.
90
+ * Note that the per-app language setting is only available in API 33+
91
+ * and it's up to the caller to check the version
90
92
*/
91
- fun openAppSettings (context : Context ) {
92
- Intent ().also { intent ->
93
- intent.setAction(Settings .ACTION_APPLICATION_DETAILS_SETTINGS )
94
- intent.addCategory(Intent .CATEGORY_DEFAULT )
95
- intent.setData(Uri .parse(" package:" + context.packageName))
96
- intent.addFlags(Intent .FLAG_ACTIVITY_NEW_TASK )
97
- intent.addFlags(Intent .FLAG_ACTIVITY_NO_HISTORY )
98
- intent.addFlags(Intent .FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS )
99
- context.startActivity(intent)
93
+ fun openAppLanguageSettings (context : Context ) {
94
+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .TIRAMISU ) {
95
+ Intent ().also { intent ->
96
+ intent.setAction(Settings .ACTION_APP_LOCALE_SETTINGS )
97
+ intent.addCategory(Intent .CATEGORY_DEFAULT )
98
+ intent.setData(Uri .parse(" package:" + context.packageName))
99
+ intent.addFlags(Intent .FLAG_ACTIVITY_NEW_TASK )
100
+ intent.addFlags(Intent .FLAG_ACTIVITY_NO_HISTORY )
101
+ intent.addFlags(Intent .FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS )
102
+ context.startActivity(intent)
103
+ }
104
+ } else {
105
+ throw UnsupportedOperationException (
106
+ " Per-app language settings are not available in this version of Android"
107
+ )
100
108
}
101
109
}
102
110
0 commit comments