1

我正在開發Android聊天應用程序。現在我想在聊天模塊中發送表情符號。我如何在聊天應用程序中實現表情符號?請指導我這個應用程序。如果有這個應用程序的任何API,那麼也建議我。謝謝Android聊天應用程序表情符號的問題

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(); 
} 
+0

只是某個時候回來回答了在這裏本應幫助你,問筆者也提到庫太 – Veer3383

回答

0

沒有具體的api可用於實現和發送emojis。您可以使用ImageSpan對象實現此目的。 TextViews和EditTexts使用Spanned/Spannable對象來存儲輸入的文本內容,而不僅僅是Java字符串。在這些Spanned/Spannable對象上,您可以爲文本上的部分定義跨度,以修改這些部分顯示的方式。所以你可以顯示圖像來代替某些部分。

檢查docs:

另外,我發現一個blog,它可能對你有所幫助。

+0

感謝好吧,我會檢查 –

+0

如果信息對您有幫助,請立即行動並接受答案。 :) –

0

This Library是您需要實施的所有Emojicons。請不要忘記分別將TextViewEditText更改爲本圖書館的EmojiconTextViewEmojiconEditText

希望這會有所幫助。

+0

謝謝我可以如何在我的項目中添加這些庫,因爲我正在使用android studio –

+0

下載此庫並將其作爲模塊導入到Android Studio中。 然後在你的項目的build.gradle文件,添加依賴這樣的.. '{依賴編譯 項目(「:ImportedProjectName」) }' – Mann

+0

它而進口模塊,它是顯示錯誤 - :指定gradle這個或Android的位置Eclipse項目 –

0

您需要在上傳前編碼表情符號。 這樣你編碼的表情符號UTF代碼

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

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

解碼

enter code here 


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