简体   繁体   English

Android聊天应用程序表情符号的问题

[英]Android chat application emoji's issue

I am working on Android chat application. 我正在研究Android聊天应用程序。 Now I want to send emoji's in my chat module. 现在,我想在聊天模块中发送表情符号。 How can i implement emoji' in chat application? 如何在聊天应用程序中实现表情符号? Please guide me for this app. 请引导我使用此应用。 If there is any API for this app then also suggest me. 如果此应用程序有任何API,也建议我。 Thanks 谢谢

  public void callAsynchronousTask() {
    final Handler handler = new Handler();
    timer = new Timer();
    TimerTask doAsynchronousTask = new TimerTask() {
        @Override
        public void run() {
            handler.post(new Runnable() {
                public void run() {
                    try {
                        new GetSingleChat(Chat_Detail_Single.this).execute(friend_id);

                    } catch (NullPointerException e) {

                    }
                }
            });

        }
    };
    timer.schedule(doAsynchronousTask, 1000, 1000);

} 

@Override
public void onClick(View v) {

    switch (v.getId()) {
        case R.id.btncamera:
            Dialog_Manager.chooseImage(Chat_Detail_Single.this, "singlechat");
            break;
        case R.id.img_back:
            timer.cancel();
            finish();
            break;
        case R.id.btnsend:
            String message_ = edt_mes.getText().toString();
            if (message_.replace(" ", "").length() == 0) {

            } else {
                edt_mes.setText("");
                new  Send_chat_message(Chat_Detail_Single.this).execute(SharedPref.getUserID(this), friend_id, "mes", message_);

            }
            break;

    }
} 
      public static void get_chat_data(List<Chat_prop> fetch_chat) {
    MyCustomList.clear();
    MyCustomList.addAll(fetch_chat);

    try {
        if (adptor == null) {

            adptor = new Single_Chat_Adap(activity,
                    MyCustomList);
            Chat_Detail_Single.listView.setAdapter(adptor);
            Chat_Detail_Single.listView.setSelection(MyCustomList
                    .size() - 1);
            lastCount = MyCustomList.size();
        } else {

            if (lastCount != MyCustomList.size()) {
                lastCount = MyCustomList.size();
                adptor.notifyDataSetChanged();
                Chat_Detail_Single.listView
                        .setSelection(MyCustomList.size());

            }


        }
    } catch (NullPointerException e) {

    } catch (Exception e) {
        // TODO: handle exception
    }

}
       @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    try {

        if (requestCode == Dialog_Manager.Gallery_Intent
                && resultCode == RESULT_OK && data != null) {

            File direct = new File(
                    Environment.getExternalStorageDirectory() + "/Fun You");
            if (!direct.exists()) {
                if (direct.mkdir())
                    ;
            }
            long time = System.currentTimeMillis();
            capturepath1 = direct.getAbsolutePath() + "/" + time + ".jpg";
            File file = new File(capturepath1);
            Uri outputFileUri = Uri.fromFile(file);
            Uri selectedImage = data.getData();
            imagePath = getPath(selectedImage);
            Intent cropIntent = new Intent("com.android.camera.action.CROP");
            Uri contentUri = selectedImage;
            cropIntent.setDataAndType(contentUri, "image/*");
            cropIntent.putExtra("crop", "true");
            cropIntent.putExtra("aspectX", 1);
            cropIntent.putExtra("aspectY", 1);
            cropIntent.putExtra("outputX", 1000);
            cropIntent.putExtra("outputY", 1000);
            cropIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
            cropIntent.putExtra("return-data", true);
            startActivityForResult(cropIntent, 3);

        } else if (requestCode == Dialog_Manager.Camera_Intent
                && resultCode == RESULT_OK) {

            File direct = new File(
                    Environment.getExternalStorageDirectory() + "/Fun You");
            if (!direct.exists()) {
                if (direct.mkdir())
                    ;
            }
            long time = System.currentTimeMillis();
            capturepath1 = direct.getAbsolutePath() + "/" + time + ".jpg";
            File file = new File(capturepath1);
            Uri outputFileUri = Uri.fromFile(file);
            File photos = new File(imagePath);
            Uri selectedImage = Uri.fromFile(photos);
            Intent cropIntent = new Intent("com.android.camera.action.CROP");
            Uri contentUri = selectedImage;
            cropIntent.setDataAndType(contentUri, "image/*");
            cropIntent.putExtra("crop", "true");
            cropIntent.putExtra("aspectX", 1);
            cropIntent.putExtra("aspectY", 1);
            cropIntent.putExtra("outputX", 1000);
            cropIntent.putExtra("outputY", 1000);
            cropIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
            cropIntent.putExtra("return-data", true);
            startActivityForResult(cropIntent, 3);

        } else if (requestCode == 3) {
            try {
                Bitmap thumbnail = null;
                Bundle extras = data.getExtras();
                if (extras != null) {
                    thumbnail = extras.getParcelable("data");
                    Bitmap bm = thumbnail;
                    bm = ExtraMethods.decodeFile(capturepath1);
                    bm = ExifUtils.rotateBitmap(capturepath1, bm);
                    // new Uplaod_image().execute(capturepath1);
                    new Send_chat_message(Chat_Detail_Single.this).execute(SharedPref.getUserID(this), friend_id, "image", capturepath1);
                }

            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    } catch (Exception e) {
        Toast.makeText(getApplicationContext(), e + "", Toast.LENGTH_LONG)
                .show();
    }

}
 public String getPath(Uri uri) {
    if (uri == null) {
        return null;
    }
    String[] projection = {MediaStore.Images.Media.DATA};
    Cursor cursor = getContentResolver().query(uri, projection, null, null,
            null);
    if (cursor != null) {
        int column_index = cursor
                .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        cursor.moveToFirst();
        return cursor.getString(column_index);
    }
    return uri.getPath();
}

There is no specific api available to implement and send emojis. 没有可用于实现和发送表情符号的特定api。 You can achieve this using ImageSpan objects. 您可以使用ImageSpan对象来实现。 The TextViews and EditTexts use Spanned/Spannable objects to store the entered text content, not just mere Java Strings. TextViews和EditTexts使用Spanned / Spannable对象来存储输入的文本内容,而不仅仅是Java字符串。 On these Spanned/Spannable objects you can define spans for sections on the text that modifies the way that those sections are shown. 在这些Spanned / Spannable对象上,您可以为文本上的部分定义跨度,以修改这些部分的显示方式。 So you can display images in place of certain sections. 因此,您可以显示图像来代替某些部分。

Check the docs: 检查文档:

Also, I found a blog , it might be helpful for you. 另外,我发现了一个博客 ,可能对您有所帮助。

This Library is all you need to implement Emojicons . 该库是实现Emojicons所需的Emojicons Just don't forget to change your TextView s and EditText s to this Library's EmojiconTextView s and EmojiconEditText s respectively. 只是不要忘记将TextViewEditText更改为该库的EmojiconTextViewEmojiconEditText

Hope this helps. 希望这可以帮助。

You need to encode emoji before upload. 上传之前,您需要对表情符号进行编码。 in this way you encode emoji to UTF code 通过这种方式,您可以将表情符号编码为UTF代码

try {
                String mystring = URLEncoder.encode(strComments, HTTP.UTF_8);
                param.add(new BasicNameValuePair("comment", mystring));

            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }

for decoding 用于解码

enter code here


try {
            String Title = URLDecoder.decode(comment, "UTF-8");
            holder.tvComment.setText(Title);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM