Gautam Jain
Gautam Jain

Reputation: 671

How to send emoji in intent to whatsapp?

I know that we can send plain text to whatsapp through an intent like :

 Intent sendIntent = new Intent();
 sendIntent.setAction(Intent.ACTION_SEND);
 sendIntent.putExtra(Intent.EXTRA_TEXT,"Text to be sent on whatsapp");
 sendIntent.setType("text/plain");
 sendIntent.setPackage("com.whatsapp");
 startActivity(sendIntent);

But I want to be able to send emojis (emoticons) to whatsapp through an intent.
How is it possible? Do we have some special codes for the emojis?

Upvotes: 7

Views: 5686

Answers (2)

Noah
Noah

Reputation: 701

Use this instead of using StringBuilder

 // send message with emojis
       int waveEmojiUnicode = 0x1F44B,
           clapEmojiUnicode = 0x1F44F,
           faceTongueEmojiUnicode = 0x1F60B;
        
            char[] waveEmojiChars = Character.toChars(waveEmojiUnicode);
            char[] clapEmojiChars = Character.toChars(clapEmojiUnicode);
            char[] faceTongueEmojiChars = Character.toChars(faceTongueEmojiUnicode);
        
            String s1 = "Hi Noah ", s2 = ", TimeLY is a nice app ", s3 = ". However, I would like" + " to report a bug [ ... ]. My name is [ ... ] by the way.";
        
            String message = s1 + String.valueOf(waveEmojiChars) + s2 + String.valueOf(clapEmojiChars) + s3 + String.valueOf(faceTongueEmojiChars);

     Intent sendIntent = new Intent();
     sendIntent.setAction(Intent.ACTION_SEND);
     sendIntent.putExtra(Intent.EXTRA_TEXT, message);
     sendIntent.setType("text/plain");
     sendIntent.setPackage("com.whatsapp");
     startActivity(sendIntent);

Upvotes: 0

shivanshPurple
shivanshPurple

Reputation: 302

I used StringBuilder for this like:

int unicode = 0x1F600
StringBuilder s = new StringBuilder();
s.append("YOUR MESSAGE HERE");
s.append(Character.toChars(unicode));

The resulting string will be something like this

YOUR MESSAGE HERE😀

Copy the unicode from here But remember to change the code that you will copy from this webpage from U-1F600 to 0x1F600.

U-1F600 is the unicode but android doesn't recognizes this. 0x1F600 is the hexcode for android.

Upvotes: 1

Related Questions