Adding String in strings.xml

Hello everyone, I was wondering is there any way to add String values to strings.xml from designer property?

Thanks.

1 Like

Also I have another question

I’m creating an extension which uses a custom activity. So I want to send some value from the activity to my extension’s SimpleEvent, is there any way to do this ?

1 Like

I believe looking at the BarcodeScanner.java will help you with this.

1 Like

Thanks for the help @Ken

It was so simple :sweat_smile:
It should have been figured out on my own.:sweat_smile:

1 Like

There is no official way but there is a simple hack.

The local var is written raw here (cleanColor method has no effect). So, if you can set colorPrimary to colorPrimary + "</color>\n<string name=\"foo\">bar</string>\n<color name=\"fake\">#00000000", you are able to inject string resources.

3 Likes

Thanks @pavi2410 for your answer.
As you already said its a hack so changing in our Compiler.java file is a temporary solution. If we are going to use this feature in any extension it will not work in other builders.
Officially there should be a annotation something like @UsesStringResources.

XML resources are dying in Android ecosystem. The Android team has suggested using a Java class to hold Strings.

Are you sure you want to define string resources in XML?

1 Like

I’m actually trying to access the string resources from AndroidManifest.xml. So defining the strings in a java class is not helpful for me.

I’m trying to do something like this -

AndroidManifest.xml

<meta-data android:name="com.facebook.sdk.ApplicationId" 
        android:value="@string/facebook_app_id"/>

strings.xml

<string name="facebook_app_id">209002466552412</string>
<string name="fb_login_protocol_scheme">fb209002466552412</string>

You can directly set the meta data element’s value like

<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="209002466552412"/>
1 Like

But the problem of hardcoding is facebook app id is unique for every application. Then I have to compile the extension every time for every user.

If we can somehow manage to inject string resources from our extension java code that will be the perfect solution for this case.

1 Like

There’s no way to do what you want at the present time in extensions. We’d typically do this in core by introducing a new project property that would be updated in response to a particular property being set. The buildserver extracts this information and uses it to construct the AndroidManifest.xml and other files. In order to support this in the core system, we’d need to introduce at least a new editor and a new annotation, as well as all of the support around those to make it work. If you’d like to make an attempt at a solution and submit it as a pull request on GitHub, that’s fine, but we likely won’t support this any time soon.

4 Likes