How to change string locale of notification bar in android
Asked Answered
C

1

6

In my application, i'm changing language dynamically so if my is in foreground, notification language is coming properly but if i force close app notification is coming in device locale.

I've used following code to change context locale but after force close it is not working

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

Any help would be appreciated.

Craven answered 17/7, 2018 at 5:37 Comment(2)
check this #10833403Eliaeliades
@NileshRathod I'm setting language programatically not device languageCraven
C
0

use android.intent.action.CONFIGURATION_CHANGED

ACTION_CONFIGURATION_CHANGED

public static final String ACTION_CONFIGURATION_CHANGED Broadcast Action: The current device Configuration (orientation, locale, etc) has changed. When such a change happens, the UIs (view hierarchy) will need to be rebuilt based on this new information; for the most part, applications don't need to worry about this, because the system will take care of stopping and restarting the application to make sure it sees the new changes. Some system code that can not be restarted will need to watch for this action and handle it appropriately.

You cannot receive this through components declared in manifests, only by explicitly registering for it with Context.registerReceiver().

This is a protected intent that can only be sent by the system.

Charlotte answered 17/7, 2018 at 10:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.