0

I have an android app which retrieves text data from server.

When I hit the query in the browser the text is received properly as :

Karnataka govt launches E-Step training program for student entrepreneurs. The program is part of Karnataka Innovation & Technology Society.

When I receive the textual data in app as java.lang.String object it is received as :

Karnataka govt launches E-Step training program for student entrepreneurs. The program is part of Karnataka Innovation & Technology Society.

As you see the  character is introduced in the text/String when received as java.lang.String object.

How do I stop this from happening? I am using Volley for making requests.

Chandan Pednekar
  • 525
  • 5
  • 19
  • Maybe look at the charset [here](https://developer.android.com/training/volley/request-custom). Though I would suggest `Charset.forName("Windows-1252")` for `ISO-8859-1` as that is a patch browsers do also. – Joop Eggen Oct 15 '19 at 08:36

1 Answers1

2

That looks like an encoding issue. See for example here how a space can morph into that A. Try to explicitly tell your program which encoding you are using and make sure it matches. text is not text.

don-joe
  • 600
  • 1
  • 4
  • 12
  • I solved it myself by changing Volley response to explicitly receive data in UTF-8 encoding.
    Previously I was receiving it as
    `new String(response.data, HttpHeaderParser.parseCharset(response.headers));` where `parseCharset()` was returning `"ISO-8859-1"`

    Changed it to `new String(response.data, StandardCharsets.UTF_8);`
    Marking your comment as answer as you mentioned `Try to explicitly tell your program which encoding you are using and make sure it matches`
    – Chandan Pednekar Oct 15 '19 at 08:40