Home > Enterprise >  How to create or handle emojis in Android
How to create or handle emojis in Android

Time:12-21

I'm new here I don't know so much about stack overflow,

Now I'm creating a chatting application where I want to send emojis, I don't know how to create emojis and how to store them in device or in MySQL db. please help me out.

I have searched a lot here but found nothing related to send emoji.

CodePudding user response:

If you're making a chatting app in android studio, than you can follow the process below to add emoji in your app.

First of all, add its dependency to build.gradle(:app) file. For example:

implementation ‘com.vanniktech:emoji-google:0.6.0’

Make a layout to specify the emoji's appearance. Its main objective is to specify the emoji's size. Additionally, it will show the messages that we send. Click to create a new layout: app ->res -> layout(right-click) -> New -> Layout Resource File. The xml file would be:

<?xml version="1.0" encoding="utf-8"?>
<com.vanniktech.emoji.EmojiTextView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_marginBottom="16dp"
    app:emojiSize="30sp"
    android:textSize="30sp"
    android:textColor="@android:color/white"/>

Set up the corresponding providing here based on the emoji set the user wants to use. Make sure the user can use them anywhere in the app by configuring the EmojiManager here. click on: File -> New -> Java Class.

The Java file, which is EmojiApplication.Java would be:

import android.app.Application;

import com.vanniktech.emoji.EmojiManager;
import com.vanniktech.emoji.google.GoogleEmojiProvider;

public class EmojiApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        EmojiManager.install(new GoogleEmojiProvider());
    }
}

Now, add this class in manifest:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.emojigfg">

    <application
        android:name=".EmojiApplication"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

Now your mainAcitivity file should be:

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import com.vanniktech.emoji.EmojiPopup;
import com.vanniktech.emoji.EmojiTextView;

public class MainActivity extends AppCompatActivity {
    EditText etEmoji;
    LinearLayout llTextViews;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        etEmoji=findViewById(R.id.etEmoji);
        llTextViews=findViewById(R.id.llTextViews);

        final EmojiPopup popup = EmojiPopup.Builder
                .fromRootView(findViewById(R.id.rootView)).build(etEmoji);

        Button btnEmojis=findViewById(R.id.btnEmojis);
        btnEmojis.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                popup.toggle();
            }
        });

        Button btnSend=findViewById(R.id.btnSend);
        btnSend.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                llTextViews.addView(getEmojiTextView());
                etEmoji.getText().clear();
            }
        });
    }

    private EmojiTextView getEmojiTextView() {
        EmojiTextView tvEmoji = (EmojiTextView) LayoutInflater
                .from(getApplicationContext())
                .inflate(R.layout.text_view_emoji, llTextViews,false);
        tvEmoji.setText(etEmoji.getText().toString());
        return tvEmoji;
    }
}
  • Related