Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Decode HTML entities in android

I need to decode HTML entities, e.g. from ö to ö, and & to &.

URLEncoder.decode(str) does not do the job (convert from % notations). TextUtils has a HTMLencode, but not a HTMLdecode.

Are there any function for decoding HTML entities?

like image 790
johboh Avatar asked May 27 '10 06:05

johboh


2 Answers

The Html class is supposed to do that, however it is said that everything is not supported. It always worked for me but I never had ö so I can't tell for this one. Try Html.fromHtml(yourStr) to get the decoded string.

like image 112
Sephy Avatar answered Sep 22 '22 05:09

Sephy


Html.fromHtml(String html) is deprecated after API v24 so this is the correct way to do it

  if (Build.VERSION.SDK_INT >= 24)   {        textView.setText(Html.fromHtml(htmlString , Html.FROM_HTML_MODE_LEGACY)));     }   else   {        textView.setText(Html.fromHtml(htmlString));   } 
like image 38
Aalok Avatar answered Sep 20 '22 05:09

Aalok