Pooja Pachchigar
Pooja Pachchigar

Reputation: 111

Display \u00F0\u009F\u0098\u0098 string to emoji in android textview?

enter image description here

str = videoname.get(i);
    String toServer = str;
    String toServerUnicodeEncoded = StringEscapeUtils.escapeJava(toServer);
    viewHolder.textss.setText(toServerUnicodeEncoded);
    Log.e("emos",toServerUnicodeEncoded);

I am retrieving a string from URL using volley and the string contains emojis in it which I want to display in Android TextView. So for that, I have taken the string then passed it in StringEscapeUtils.escapeJava(toServer) and after that I am getting the emoji in "\u00F0\u009F\u0098\u0098" form, Instead of "\uD83D\uDE18" form . So how to display emoji in textview?

Upvotes: 2

Views: 5704

Answers (6)

Pooja Pachchigar
Pooja Pachchigar

Reputation: 111

String title = new String(c.getString("title").getBytes("ISO-8859-1"), "UTF-8");

While Parsing the response I used this now instead of:

String title = String(c.getString("title");

This solved my emoji issue.

Upvotes: 2

Quick learner
Quick learner

Reputation: 11457

This worked for me , Try this.

Import this library

implementation 'org.apache.commons:commons-lang3:3.4'

Then use its method to convert String(emoji code) to Emoji to show in TextView

textView.setText(StringEscapeUtils.unescapeJava(string_value));

Eg:-

Input String :- "\ud83d\ude01"

Result:-

enter image description here

Upvotes: 1

Brian Hoang
Brian Hoang

Reputation: 1111

This is html encoding string. Check code:

String txt = "\u00F0\u009F\u0098\u0098";
tvHihiView.setText(Html.fromHtml(txt));

Upvotes: 0

vishal tarsariya
vishal tarsariya

Reputation: 11

TextView txt_price = (TextView) findViewById(R.id.txt_price);

txt_price.setText("\u20B9" + " 5000");

Upvotes: -1

Adil
Adil

Reputation: 812

You don't need to convert it to unicode directly use that string code like

 TextView txt = (TextView) findViewById(R.id.txt);
        txt.setText("\u00F0");

for more unicide code check this URL

Hope this helpful to you.

Upvotes: 0

Adib Faramarzi
Adib Faramarzi

Reputation: 4064

You need to unescape your escaped String.

You can use StringEscapeUtils.unescapeJava(String) to unescape it.

The problem is fully explained here.

Upvotes: 0

Related Questions