android - 如何在android中更改通知栏的字符串区域设置

标签 android push-notification notifications android-notification-bar setlocale

在我的应用程序中,我正在动态更改语言,所以如果我的语言在前台,通知语言会正确出现,但如果我强制关闭应用程序,通知会在设备区域设置中出现。

我使用下面的代码来更改上下文语言环境,但在强制关闭后它不起作用

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)
}

如有任何帮助,我们将不胜感激。

最佳答案

使用android.intent.action.CONFIGURATION_CHANGED

ACTION_CONFIGURATION_CHANGED

公共(public)静态最终字符串 ACTION_CONFIGURATION_CHANGED 广播 Action :当前设备配置(方向、区域设置等)已更改。当发生这样的变化时,UI( View 层次结构)将需要根据这个新信息重建;在大多数情况下,应用程序不需要担心这一点,因为系统会负责停止和重新启动应用程序以确保它看到新的更改。一些无法重启的系统代码将需要监视这个 Action 并适本地处理它。

您不能通过 list 中声明的​​组件接收它,只能通过使用 Context.registerReceiver() 显式注册。

这是一个 protected Intent ,只能由系统发送。

关于android - 如何在android中更改通知栏的字符串区域设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51373909/

相关文章:

java - 具有 ArrayList 和 ListView 的 Android Array Adapter 在更改 arraylist 时不更新

android - Solrj 从 Android 索引文档

android firebase 从datasnapshot 获取字符串到外部

ios - Xcode 聊天应用程序,创建动态 View - 有点迷失

android - 如何以正确的方式android设置通知声音持续时间

android - 如何防止在 Gmail 的集成迷你浏览器中打开链接

iOS 推送通知操作未显示

ios - React-native-firebase:推送通知并不总是适用于 iOS

notifications - FIWARE-Orion Context Broker 元数据更新触发通知

android - 从 Android 服务创建实时通知