Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: How store url in string.xml resource file?

I'm trying to store a fully qualified url, with also query params:

www.miosito.net?prova&reg=bis

but it's causing a problem because &reg is similar to ® entity and android tell me that and html entity is not well written.

I need this because every locale uses a fully different set of url query param.

I tried with [[CDATA[.. ]] but this syntax disliked by xml parser.

like image 847
realtebo Avatar asked Sep 02 '12 16:09

realtebo


People also ask

What is string xml file in Android?

String. xml file contains all the strings which will be used frequently in Android project. String. xml file present in the values folder which is sub folder of res folder in project structure.In Android Studio, we have many Views such as TextView,Button,EditText,CheckBox,RadioButton etc.

In which folder can you find the string resource file strings xml Android?

You can find strings. xml file inside res folder under values as shown below.

Why do we use string xml in Android?

xml , you can easily translate your whole app into other languages. This saves you a lot of work instead of doing this the hardcoded way: Android automatically selects the correct language based on user preferences, and you don't have to worry about selecting and displaying this language.

What is string resource in Android?

A string resource provides text strings for your application with optional text styling and formatting. There are three types of resources that can provide your application with strings: String. XML resource that provides a single string. String Array.


2 Answers

The problem is not with &req but with & itself. For XML/HTML you would have to use & entity (or &), but for URLs you should rather URL-encode (see docs) strings, and in that case said & should be replaced with %26. So your final string should look like:

www.miosito.net?prova%26reg=bis

like image 110
Marcin Orlowski Avatar answered Oct 09 '22 21:10

Marcin Orlowski


Store it like this:

<string name="my_url">"www.miosito.net?prova&amp;reg=bis"</string>

Where &amp; is the XML equivelant of the ampersand symbol &.

like image 42
iTurki Avatar answered Oct 09 '22 20:10

iTurki