fun getLanguageCode(isISO3 : Boolean =false) : String{
var language = "en"
var local =Locale.getDefault()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
try {
local=BaseApplication.INSTANCE.getResources().getConfiguration().getLocales().get(0)
}catch (e:Exception){
}
}
language= if (isISO3)local.getISO3Language() else local.getLanguage()
LogUtil.d("language ",language)
return language
}
tips: 替换相关上下文及log打印。 代码为自己做个记录,有问题欢迎指出纠正