Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android string.xml resource file from server

Tags:

android

locale

As we know already e.g. we cannot change res folder values and files at runtime,

I am working on an app, in which we are supporting more than 25 language, hance APK size is increased drastically due to these string files, we are very concerned about the APK size, so we don't want to keep all these string.xml files locally in the project(inside apk).

What we are thinking is we will keep only English string.xml inside res, and all other locales string.xml should be downloaded from the server on application launch on the need basis.

So we are planning to create our own getResource( key, currentLocale), and then this will read from an XML(or text) file which will be downloaded from the server.

Please suggest any better ideas or some ways around it.

Thanks for your support.

like image 639
Lavekush Agrawal Avatar asked Dec 20 '16 10:12

Lavekush Agrawal


2 Answers

Do you know about Android App Bundle? it is a new way to publish your app to Google Play, and you don't need to refactor your code to use it, and you downloaded apk from Play Store will be more small?

From Google Developers:

The new app publishing format, the Android App Bundle, is a more efficient way to build and release your app. The Android App Bundle lets you more easily deliver a great experience in a smaller app size, allowing for the huge variety of Android devices available today. It's easy to switch. You don’t need to refactor your code to start benefiting from a smaller app.

Available in Android Studio 3.2 or later and the Unity 2018.3 beta release.

So if your project have 25 languages and my device have configured English as the device language, when I go to download your APP it will get only the strings.xml file the others strings.xml remain in Google Play, and if you change your device language to Portuguese, Google Play App will try to get the new strings.xml for Portuguese and delete the old file with English text.

Please before you try another option try this first as it is the recommended way and you do not need to do anything else, just generate your app as App Bundle and send to Play Store and if you want to test, download your app then change the device language you will see Google Play downloading the app's new language again.

Hope I helped you anyway.

like image 126
Pedro Massango Avatar answered Sep 19 '22 17:09

Pedro Massango


Unfortunatelly resources couldn't be changed after compilation. The only way for you is to download language shema from server (i.e when app starts) and save it (or update if needed) in sqlite, file or in shared preferences (the storage options: https://developer.android.com/guide/topics/data/data-storage.html#filesInternal).

like image 20
Leśniakiewicz Avatar answered Sep 20 '22 17:09

Leśniakiewicz