Rag*_*ini 6 notifications android push-notification setlocale android-notification-bar
在我的应用程序中,我正在动态更改语言,因此如果我在前台,通知语言将正确出现,但如果我强制关闭应用程序通知将出现在设备区域设置中。
我使用以下代码来更改上下文语言环境,但在强制关闭后它不起作用
fun wrapContext(context: Context?, locale: Locale): Context? {
if (context == null) return null
val configuration = context.resources.configuration
if (getSystemLocale(configuration) === locale) {
return context
}
setSystemLocale(configuration, locale)
val res = context.resources
res.updateConfiguration(configuration, res.displayMetrics)
return context.createConfigurationContext(configuration)
}
Run Code Online (Sandbox Code Playgroud)
任何帮助,将不胜感激。
使用android.intent.action.CONFIGURATION_CHANGED
ACTION_CONFIGURATION_CHANGED
public static Final String ACTION_CONFIGURATION_CHANGED 广播操作:当前设备配置(方向、区域设置等)已更改。当发生这样的变化时,UI(视图层次结构)将需要根据这些新信息重建;在大多数情况下,应用程序不需要担心这一点,因为系统将负责停止和重新启动应用程序以确保它看到新的更改。一些无法重新启动的系统代码需要监视此操作并进行适当的处理。
您无法通过清单中声明的组件接收此信息,只能通过使用 Context.registerReceiver() 显式注册它。
这是一个受保护的意图,只能由系统发送。
| 归档时间: |
|
| 查看次数: |
749 次 |
| 最近记录: |