Regional Preferences
Regional preferences setting is only available in API level 34 (Android 14) or higher.
Android 14 adds a new setting page called Regional Preferences where user can personalize their temperature unit and first day of week preferences.
To access this page, open Settings app and navigate to System > Languages & input > Regional preferences. The page will look something like this:
Basic Usage​
We also have a few methods to utilize regional preferences within our applications.
1. Opening Regional Preferences Setting Page​
To open the regional preferences setting page directly from our application, simply use ACTION_REGIONAL_PREFERENCES_SETTINGS
intent action:
import android.content.Context
import android.content.Intent
import android.os.Build
import android.provider.Settings
import androidx.core.content.ContextCompat.startActivity
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
startActivity(context, Intent(Settings.ACTION_REGIONAL_PREFERENCES_SETTINGS), null)
}
2. Getting Current Temperature Unit Preference​
To retrieve the user's temperature unit preference, use getTemperatureUnit()
method:
import androidx.core.text.util.LocalePreferences
/**
* Get the current temperature unit setting.
*
* Possible values:
* - [LocalePreferences.TemperatureUnit.DEFAULT] : Default
* - [LocalePreferences.TemperatureUnit.CELSIUS] : Celsius
* - [LocalePreferences.TemperatureUnit.FAHRENHEIT] : Fahrenheit
* - [LocalePreferences.TemperatureUnit.KELVIN] : Kelvin
*/
val temperatureUnitPref = LocalePreferences.getTemperatureUnit()
3. Getting Current First Day of Week Preference​
To retrieve the user's first day of week preference, use getFirstDayOfWeek()
method:
import androidx.core.text.util.LocalePreferences
/**
* Get the current first day of week setting.
*
* Possible values:
* - [LocalePreferences.FirstDayOfWeek.DEFAULT] : Default
* - [LocalePreferences.FirstDayOfWeek.MONDAY] : Monday
* - [LocalePreferences.FirstDayOfWeek.TUESDAY] : Tuesday
* - [LocalePreferences.FirstDayOfWeek.WEDNESDAY] : Wednesday
* - [LocalePreferences.FirstDayOfWeek.THURSDAY] : Thursday
* - [LocalePreferences.FirstDayOfWeek.FRIDAY] : Friday
* - [LocalePreferences.FirstDayOfWeek.SATURDAY] : Saturday
* - [LocalePreferences.FirstDayOfWeek.SUNDAY] : Sunday
*/
val firstDayOfWeekPref = LocalePreferences.getFirstDayOfWeek()