TOP
TOP

Reputation: 2614

Can I use Firebase remote config for updating strings.xml of Android app?

Well known that Firebase Remote Config is a cloud service that lets you change the behavior and appearance of your app without requiring users to download an app update.

I was wondering that can I use Firebase Remote Config for updating strings.xml?

Sometime I need to update file strings.xml (for example: correct the translation of locale languages). And to do this I have to update my app.

It's great if we can store the strings in server like Firebase.

Upvotes: 4

Views: 3348

Answers (2)

Ravindra Barthwal
Ravindra Barthwal

Reputation: 380

Dynamically updating strings.xml is not possible but there's a solution to this. I ran into the same problem when I wanted to do A/B testing with Firebase Remote Config. So I created FString library for android and it provides a smart solution. It currently powers Mouve Android App on production.

Installation

  • In your project's module build.gradle add this dependency
implementation 'com.ravindrabarthwal.fstring:fstring:1.0.0'
  • In your Android Application class add the following code
import com.example.myapp.R.string as RString // Import your string 

class MyApp: Application() {

    override fun onCreate() {
        super.onCreate()
        FString.init(RString::class.java) // Initializes the FString
    }

}

Usage

To access the strings

  // This is how you get strings without FString
  context.getString(R.string.my_app_name) // This is how you normally do

  // To get the string using FString use
  FString.getString(context, R.string.my_app_name)

  // If you prefer extension function use
  context.getFString(R.string.my_app_name) // This is how FString works ;)

To update the FString values

  /*
   * Assume this JSON is coming from server. The JSON string 
   * must be parseable to a JSON object with key and value pairs
   */
  var jsonFromServer = """
      {
        "my_app_name": "MyApp v2.0",
        "some_other_string": "this is so cool",
      }
  """.trimIndent()

  // This will update the SharedPreference using keys from
  // above JSON and corresponding value. The SharedPreference will
  // not save any key that is not is strings.xml
  FString.update(context, jsonFromServer) 

Check the library documentation for more info. If you find the answer helpful upvote this and mark it as the answer.

Upvotes: 3

asdcvf
asdcvf

Reputation: 199

I think you cannot do it through Firebase, just need to update apk.

Upvotes: 2

Related Questions