Android 推送通知 Intent 未使用自定义应用内区域设置本地化应用活动

问题描述

我有一项应用功能,允许用户选择自己的自定义应用内语言(与设备语言分开)。

当我通过点击应用程序图标打开应用程序时,语言更新正常。我用这个逻辑来改变基础上下文:

override fun attachBaseContext(newBase: Context) {
            val updatedContext = LocaleUtils.getLocalizedContextwrapper(getInAppLocale(newBase),locale)
            super.attachBaseContext(updatedContext)
}
fun getLocalizedContextwrapper(context: Context,targetLocale: Locale): Contextwrapper {
            return LocaleUtils(getLocalizedContext(context,targetLocale))
}
fun getLocalizedContext(context: Context,targetLocale: Locale): Context {
            val newConfig = getLocalizedConfig(context,targetLocale)
            return context.createConfigurationContext(newConfig)
}
 private fun getLocalizedConfig(context: Context,targetLocale: Locale): Configuration {
            val resources: Resources = context.resources
            val config: Configuration = resources.configuration
            config.setLocale(targetLocale)

            when {
                Build.VERSION.SDK_INT >= Build.VERSION_CODES.N -> {
                    val localeList = LocaleList(targetLocale)
                    LocaleList.setDefault(localeList)
                    config.setLocales(localeList)
                }
                else -> {
                    Locale.setDefault(targetLocale)
                }
            }
            return config
}

我还确保活动目的地是一个新任务:

intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK)

但是每当我收到推送通知并点击它以导航到应用程序时,内容都未本地化。我可以通过设备系统设置设置不同的语言来验证这一点。但是,当我终止应用程序并重新启动它时,该应用程序会照常从我的共享首选项中获取自定义应用程序内语言。

此外,当我点击推送通知时,我可以看到我的 BaseActivity 正在调用 attachBaseContext() 并且正在更新正确的应用内区域设置。

有没有人遇到过这个问题?任何帮助将不胜感激。

在此先感谢您!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)