2

I have the problem that somewhere when i save my textfield the accents disapear and don't get saved to de bd.


Example :

entrance : " la meva ocupació és x " What the bd saves : "la meva ocupaci"


I think I may fail in some of these parts:

when i pick the data from the textfield:

title = (EditText)findViewById(R.id.title);

when i convert it to string :

String post_title = title.getText().toString();

when i put it on the list:

List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("title", post_title));

Full code : http://pastebin.com/trrPEG33

When i do an insert on the bd it takes accents with no problems

When i recive data from the bd this data contains the accents and they are shown perfectly

I think the problem may be on the save .

I'll be really gratefull on any help. Sorry for my english.

Saint
  • 480
  • 1
  • 6
  • 21
tknbr
  • 139
  • 1
  • 13
  • Wow! I have never had problems with the accents, even if storing them into databases. I do recommend you to debug step by step to find which line destroys the accents, and look for a solution dealing with encoding (UTF8) – Didac Perez Parera Aug 28 '13 at 10:18
  • sorry, i am kind of new in android, how can i do that? – tknbr Aug 28 '13 at 10:25
  • Put a breakpoint in the first line where you get the String, and go step by step (Run->Step Over) looking for the values. You must run the application in Debug mode (Run->Debug or F11). – Didac Perez Parera Aug 28 '13 at 10:37
  • Could you add your JSonParser class source? I suspect the problem is at the Http POST request sent to the REST service. – Tomas Narros Aug 28 '13 at 10:49
  • sure, here it is http://pastebin.com/5icrKWpH – tknbr Aug 28 '13 at 11:02
  • If you are ever doing a call to `URLEncodedUtils.parse`, note that that method doesn't handle non-ASCII appropriately, see my comment on http://stackoverflow.com/a/13592324/320594. – Jaime Hablutzel Dec 24 '16 at 23:13

1 Answers1

3

The problem seems to rely on the REST service invocation at your JSonParser class, wich is not taking into account the charsets used at Android and at the service are different.

By default, Android uses UTF-8 encoding, and I suspect your service uses ISO-8859-1 (as seen on the response handling piece of the code).

To fix it, you must inform the URlEncodedFormEntity of the charset to use pfor the encoding:

for the POST request:

 httpPost.setEntity(new UrlEncodedFormEntity(params, "iso-8859-1")); //line 108

for the GET request:

String paramString = URLEncodedUtils.format(params, "iso-8859-1"); //line 117

This should be enough.

Tomas Narros
  • 13,390
  • 2
  • 40
  • 56
  • Thanks you a lot, that helped me and i finally finished my app. In my case i had to change de iso_8859-1 for utf-8, and all worked perfectly. Sry i can't vote up, i don't have the enough reputation :S – tknbr Aug 28 '13 at 12:15