Android - Convert Unicode to HTML Entity - android

As mentioned in Emoji in strings.xml file? you need to use Unicode smileys like these:
https://apps.timwhitlock.info/emoji/tables/unicode
as HTML Entity but why didn't he mentioned how to convert them to HTML Entity.
I tried all kind of online converters like https://www.online-toolz.com/tools/text-html-entities-convertor.php but they don't convert stuff like U+1F601 to anything.
Can someone enlighten me?

This is easier than you might think: U+1F601 corresponds to 😁.

Slight modification to Henry's answer, You may use as follows.
<string name="hello_world">Hello world! 😁</string>
// this is using in decimal
But I have found that it is giving run time errors in Lollipop and below.
It works on marshmallow and above.

Related

How to set Default language other than english in Android?

I have a project by my client that has built successfully in his system but as he sent to me I am unable to compile it because of unicode characters (Latin characters) in default strings.xml under res. I believe its the default localizations file but its forcing me to convert it into English but not parsing Latin Characters into it.
e.g.
<string name="old_questions">Questões e soluções dos anos anteriores</string>
Check that the XML is in UTF-8 and has
<?xml ... encoding="UTF-8"?>
or defaulted
<?xml ... ?>
I tried your text in my studio , well it is working fine. You could also update question with your error , that would help understand it better.
Another workaround for small texts would be to simply escape it.
<string name="Example">Example character \u0026</string>
go to this website : https://unicode-table.com/en/#control-character and this could help you .
Make sure your string file is in the default values folder.
You can check the android developers link for better understanding.
To help you better please post the exact error you get while compiling the code.

Use Unicode characters in strings.xml

I have the following unicode character that I want to use in a string: 🚕
I have found its hex and decimal code through this:
While I know how to use the "&" symbol in a string in strings.xml by doing this:
<string name="Example">Example character &</string>
I cannot use the car symbol.
How can I use this unicode character in a string in strings.xml?
Update One:
Following the first solution of using this: 🚗
I got the following error:ERROR IN APPLICATION: input is not valid Modified UTF-8:
It's
<string name="Example">Example character \u0026</string>
See more unicode characters here:
http://www.utf8-chartable.de/unicode-utf8-table.pl?number=1024&utf8=0x
if you go Unicode site : https://unicode-table.com/en/#control-character and click at this Unicode that says U+00AE you mustn't write the + symbol if you want copy paste this example at strings.xml
:) :) :)
<string name="example">"\u00AE"</string>
Few important Unicode symbols for android strings.xml
<string name=”Rs”>\u20B9</string>
<string name=”filled_bullet”>\u25CF</string>
<string name=”linear_bullet”>\u25CB</string>
<string name=”rect_bullet”>\u25A0</string>
<string name=”blank_rect”>\u25A1</string>
<string name=”true_tick”>\u2713</string>
<string name=”star”>\u2605</string>
Full link is here
<string name="ic_happy_font"></string>
or
<string name="edit">🚕</string>
Check that the XML is in UTF-8 and has <?xml ... encoding="UTF-8"?> or defaulted <?xml ... ?>.
First the Unicode code point is U+1F695 which is decimally 128661 (not ...3).
In XML content your approach is basically correct.
🚕
🚕
The error mentions "modified" UTF-8. This just means the code point U+0000, a binary 0, is also encoded as multi-byte sequence of bytes with high bit set. This is support for C where a "string" ends on a NUL byte.
As the TAXI code point needs 4 UTF-8 bytes, it might be that the XML on Android only supports less long UTF-8 sequences. At least for numeric entities &#...;.
If the entities are a problem, use an UTF-8 capable editor and paste the TAXI from the clipboard.
You might try whether there is a work-around, whether u-escaped chars are read (probably not):
\uD83D\uDE95
A last wild attempt would be to use
<?xml version="1.1" ...
I think the code point you have in your example is an ellipsis. As per this page, try
🚗
If anyone gets underlined space although you didn't intent it, you can avoid this by using unicode code point of space
For example:
<string name="conditions">By signing in you agree to our <u>Terms &
Conditions.</u></string>
would also underline space before 'Terms & Conditions'
solution:
<string name="conditions">By signing in you agree to our\u0020<u>Terms &
Conditions.</u></string>

How to use escape characters in XML

How can I use escape characters in XML?
The situation is, I am a new android developer, and I need a string which need to be printed in 2 lines (other wise no space). This string is in string.xml file. I need to use /n line break character to break the string, but I don't know how to do it in XML file. Please help.
See reference http://developer.android.com/guide/topics/resources/string-resource.html#String
line break symbol is \n
/n - is wrong.
and you can write it in xml like it is.
Example:
<string name="multiline_text">line 1.\nline2.</string>
I'm not familiar with Android development but have you checked out CDATA? Refer to this link.
Basically, you wrap your string value like so:
<![CDATA[string value]]>
You can use double quotes:
<string name="mystring">"One line\nAnother line"</string>
You can use the character entity
to indicate a linefeed.

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.
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
Store it like this:
<string name="my_url">"www.miosito.net?prova&reg=bis"</string>
Where & is the XML equivelant of the ampersand symbol &.
Percent encoding may do the trick: http://en.wikipedia.org/wiki/Percent-encoding
You'll basically have something like this: www.miosito.net?prova%26reg=bis
You can enclose your url in double quotes, something like :
<string name="my_url">"www.miosito.net?prova&reg=bis"</string>
This is a recommended way to enclose string resources in Android.
Update 1 : Have a look at the following link for more info :
http://developer.android.com/guide/topics/resources/string-resource.html#FormattingAndStyling
Update 2:
#WebnetMobile.com : Correct, indeed :)
'&' is being treated a special character by xml and enclosing in quotes doesn't work. I tried out
www.miosito.net?prova%26reg=bis
and it didn't work out either. I even tried enclosing it in quotes but still didn't work. Am I missing something ?
Meanwhile, the following does work :
<string name="my_url">www.miosito.net%1$sprova%2$sreg=bis</string>
and then in code :
Resources resources=getResources();
String url=String.format(resources.getString(R.string.my_url),"?","&") ;
The '%1$s' and '%2$s' are format specifiers, much like what is used in printf in C. '%1$s' is for strings, '%2$d' is for decimal numbers and so on.

How to put Hebrew character in Android JAVA file?

For Android Platform:
I need to put Hebrew Character ₪ and some more like אורנג in string to check with the incoming data in java file. When I put this character It shows an error like "Some characters can not be mapped using "Cp1252" character encoding. Either change the encoding or remove the characters which are not supported by the "Cp1252" character encoding". These values are coming from SQLite database. Please see the attached snap. How can I solve this? Kindly give me some useful suggestions. Looking forward to hear from anybody who has a suggestion for me. Thanks.
Please open your eclipse.ini file from your eclipse folder with Note Pad and put the following permission into that.
-Dfile.encoding = UTF-8
Some more options as well:
For setting the encoding on a per WorkSpace basis, use Preferences->General->Workspace
To set the encoding on a per project basis open project properties and change to UTF-8
Hope this one help.
I think you'll need UTF-8 encoding for that.
These things are a little bit confusing. Reading this might clear some of the mist around encodings and character sets.
I think this may useful to you.
Keep this hebrew word in string.xml file. You can retrieve as
in String.xml
place hebrew word here
In java code:
String s=getString(R.string.hebrew_word);
Use this string as you want..

Categories

Resources