After creating a database, i'm using a listview do display some lines of it. I'm facing a encoding problem trying to display a 'Ç' or 'ç' and many other characters. What is the correct approach to solve the problem?
Regards
I'd recommend to convert all the text you have to UTF-8. Android's default charset is UTF-8 and you can configure your tools (eclipse, operating system default encoding, etc.) to always use UTF-8 - this way any text you will be entering or copying into files will be UTF-8 and your worries are much less.
If you have some other external data sources like files or HTML pages, you should convert them to UTF-8 first. There are number of tools you can use - various text editors for Windows/OSX (Notepad++ my favourite), iconv unix command line tool etc. to convert between various encodings.
UTF-8 is also used by JSON which is most commonly used format for mobiles for data exchange.
You have to check defaultCharset vs your desired charset.
and you have the Charset utility at your disposal.
Related
I have ÷ in .txt file in my android. When this division symbol is shown on android device, I see "�"
To make it worse, my laptop doesn't have division sign on keyboard. I used the above sign from wikipedia.
Any guess how can I resolve this.
You should use the Unicode value for any symbols such as the division symbol you have here.
Try the Unicode U00F7.
When using it within a String format like "\u00F7".
The problem is most likely a font issue, or possibly a unicode encoding issue. The character you pasted is unicode codepoint 0xF7: if the font being used to display your text file does not have a specific glyph for this codepoint, then it will render it using some reserved glyph like the question mark diamond you show. The solution in this case would be to install and use a font which includes an appropriate glyph for this codepoint. For instance, if it is displayed correctly in your web browser, then find out what font your browser is using, and try that. Of course, whether or not you can change the font used to display your text file depends on the application (at least I think: I don't think Android fixes the font across all apps).
Alternatively, it could be an encoding problem. For instance, if you're saving your text file in Latin-1 encoding, then this character will be stored in a single byte with value 0xF7. If the app that you're viewing the file with is assuming it's UTF-8, for instance, then this byte will be interpreted as the first of a multi-byte character, or it may even be invalid. If this is the case, you just need to make sure the encoding you use to save the file is the same as the one being used to display the file. Again, this would be application specific.
I'm trying to display utf-8 character in a ListView in my android app, but what appears is series of question mark????? This is what the output looks like:
[{"ImageID":"1","ItemID":"Item1","ItemID_AM":"????
???","ImagePath":"http:\/\/10.0.2.2\/android\/Pagination\/pics\/pic_a.png"},{"ImageID":"2","ItemID":"Item2","ItemID_AM":"????
????","ImagePath":"http:\/\/10.0.2.2\/android\/Pagination\/pics\/pic_b.png"},...
I already used: header('content-type: application/json; charset=utf-8');
But nothing changed. Can someone help please?
Thanks.
Java strings use Unicode and the JSON strings are UTF-8 encoded. Most likely, you must convert the UTF-8 JSON to Unicode.
Search: java string utf8, for example How to convert Strings to and from UTF8 byte arrays in Java
The easiest way though, would be to let an appropriate JSON library do the decoding. Maybe org.json - Android or How to parse JSON in Android is of help.
Update:
Maybe everything is fine and it is just the font not capable of displaying the needed characters. If this is the case, the solution to the problem would be to install an appropriate font.
I'm developing an Android app and when it was suposed to write words like "não" or "cabeça", with characters with "~" or "ç" for example, it writes "ã" or "ç". I already checked source files encoding and it is UTF-8.
Looks like UTF8 interpreted as ISO-8859-x.
In theory, you could supply the javac compiler -encoding UTF-8 on the command line but that would be the wrong solution.
Instead, move all your user-facing strings to an XML resource file. In there unicode character encoding works out of the box.
Further reading: http://developer.android.com/guide/topics/resources/string-resource.html
I just got my app strings translated to italian but having issues in displaying them on android device.
For example, one of the word is "velocità", on the device the last character à is shown as junk character.
Any pointers on how can I resolve it. The above word is present in the raw-it folder in a .txt file.
I assume you have the txt file not encoded as utf-8. Right click on the file in Eclipse and then properties. Set it to UTF-8. (You might need to copy the text into it again to make the characters appear ok).
UTF8 encoding supports foreign language characters. Try using UTF8 encoding. if that doesnt work then the problemmight be because of the font used.Good Luck.
Does the android support Unicode natively?
But in String.xml we have to edit it with UTF-8 ??
Any way to check the string's encoding? unicode or utf-8 ?....
Android does support Unicode.
Since you seem to be confused about the relationship between UTF-8 and Unicode, I recommend that you save yourself a lot of pain and just read The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets.
If you mean UTF-16 or UTF-8 - Android works with UTF-8
Android supports Unicode characters in UTF-8 encoding - but lacks proper fonts and a complex text rendering system do display many scripts and languages properly.