Skip to content Skip to sidebar Skip to footer

Android - Issue With Encoding Arabic Words

I face problem in encoding Arabic response from web , I am using volley to call web service my tries to fix this issue. I created custom request then parse network response with u

Solution 1:

finally I figure nice solution to all who face encoding issue

First : make sure your android studio encoding utf-8 ,

File -> Settings -> Editor -> File Encodings choose utf-8 in encoding project

reference

Second: here is the trick , we need to discover what encoding did we receive , we can approach that in parseNetworkResponse method by called response.headers.get("content-type").

in my case I got charset:utf-8 that mean encoding in utf-8 but in fact its not , how we discover real encoding type here is site detect encoding https://2cyr.com/decode/ , just past text in site and made site handle Select encoding : auto detect

it will return pasted text with all encoding scroll down to find write encoding (you will see your writing in original language )

get source encoding: , displayed as:

in my case I found source encoding : utf-8 displayed as: windows-1254

this why I create method fix encoding issue

publicstaticStringfixEncodingUnicode(String response) {
            String str = "";
            try {
                                             // displayed as    desired encoding
                                                     ^                 ^
                                                     |                 |
                str = newString(response.getBytes("windows-1254"), "UTF-8");
            } catch (UnsupportedEncodingException e) {

                e.printStackTrace();
            }

            String decodedStr = Html.fromHtml(str).toString();
            return decodedStr;
        }

Post a Comment for "Android - Issue With Encoding Arabic Words"