Decoding Urdu Codes In Android
I am calling an API and receiving the response in both English and Urdu. The response is stored in a string and the urdu part shows character text like '/u024/'. I have been imple
Solution 1:
Your response in Unicode, try this
TextView tv=(TextView)findViewById(R.id.textViewmyView);
finalTypefacetf= Typeface.createFromAsset(this.getAssets(),"asunaskh.ttf");
tv.setTypeface(tf);
tv.setText(Html.fromHtml(yourText);
add this if above doesn't work
Stringstr = myString.split(" ")[0];
str = str.replace("\\","");
String[] arr = str.split("u");
String text = "";
for(int i = 1; i < arr.length; i++){
int hexVal = Integer.parseInt(arr[i], 16);
text += (char)hexVal;
}
or this
textview.setText(Html.from(StringEscapeUtils.unescapeJava(unicode))); //this method
for more : see this How to use unicode in Android resource?
How to convert a string with Unicode encoding to a string of letters
Solution 2:
Try this font instead your current font: http://www.quran.or.kr/urdu/font/asunaskh.ttf
try {
txtGhost.setTypeface(Typeface.createFromAsset(this.getAssets(),"asunaskh.ttf"));
txtGhost.setText("ur text");
}
catch(Exception ex) {
Log.e("TAG", ex.toString());
}
And, what errors did you get in your case?
More information about language support: how to add language support to android
Post a Comment for "Decoding Urdu Codes In Android"