11package com.asemlab.samples.ui
22
33import android.Manifest
4+ import android.app.LocaleConfig
5+ import android.app.LocaleManager
46import android.content.pm.PackageManager
57import android.os.Build
68import android.os.Bundle
9+ import android.os.LocaleList
710import android.view.View
811import androidx.annotation.RequiresApi
912import androidx.appcompat.app.AppCompatActivity
@@ -36,6 +39,11 @@ class MainActivity : AppCompatActivity() {
3639 true
3740 )
3841
42+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .UPSIDE_DOWN_CAKE ) {
43+ // TODO Set per-app supported languages dynamically
44+ updateSupportedLocales()
45+ }
46+
3947 }
4048
4149 fun selectFragment (view : View ) {
@@ -53,5 +61,20 @@ class MainActivity : AppCompatActivity() {
5361 fragmentTransaction.commit()
5462 }
5563
64+ @RequiresApi(Build .VERSION_CODES .UPSIDE_DOWN_CAKE )
65+ fun updateSupportedLocales () {
66+ val localeManager = applicationContext
67+ .getSystemService(LocaleManager ::class .java)
68+
69+ // For getOverrideLocaleConfig
70+ val overrideLocaleConfig = localeManager.overrideLocaleConfig
71+ val supportedLocales = overrideLocaleConfig?.supportedLocales
72+
73+ // For setOverrideLocaleConfig, update supported and remove old ones
74+ localeManager.overrideLocaleConfig = LocaleConfig (
75+ LocaleList .forLanguageTags(" en-US,ja-JP,ar" )
76+ )
77+
78+ }
5679
5780}
0 commit comments