mardi 15 septembre 2015

Decoding e-acute from SQLite database in Android

I have a sqlite database that contains (a portion) the following string:

"to describe garments historically worn by Métis and voyageurs in the fur trade"

When I view the string using SQLiteStudio I can see that the e-acute is properly saved in the database as "é" or at least it displays it as the proper character.

However, when I try and load this string from the database in my Android App it displays the e-acute as a chinese character in both the Eclipse LogCat and in the ListView control I am using (see image capture below).

enter image description here

I have checked the database using

PRAGMA encoding;

and it shows the database to be UTF-8 encoded.

I use the following code to read the string/specific column from the database

expectations.add(cursor.getString(0));

where expectations is an List of Strings.

So then I tried each of the following solutions to see if there was a conversion needed.

  • Normalizer.normalize(cursor.getString(0), Normalizer.Form.NFC);

  • Html.fromHtml(cursor.getString(0)).toString();

  • String newString = new String(cursor.getString(0).getBytes("UTF-8"), "UTF-8"); [within try/catch block]

All based upon questions asked by others on SE.

I also changed my query to use both (not at the same time):

COLLATE UNICODE and COLLATE LOCALIZED

but neither of these worked. At this point I am not sure what else to try. Any suggestions would be appreciated.

Further Info: I have inserted the data in the database using PHP in Windows using the SQLite3 class. The file was created in Notepad++ and was saved with and without UTF-8 encoding but that didnt seem to make a difference either.

Aucun commentaire:

Enregistrer un commentaire