我試圖在我的EditText
字段中使用表情符號。但問題是,當我嘗試將表情符號轉換爲hexa時,該值不正確。從Android中的editText編碼和解碼錶情符號
我用這個函數在Hexa中獲取表情符值。
public static String escapeJavaString(String st){
StringBuilder builder = new StringBuilder();
try {
for (int i = 0; i < st.length(); i++) {
char c = st.charAt(i);
if(!Character.isLetterOrDigit(c) && !Character.isSpaceChar(c)&& !Character.isWhitespace(c)){
String hexa= String.valueOf(c);
int code = (int)c;
if(!(code >= 0 && code <= 255)){
hexa= "0x"+Integer.toHexString(c);
}
builder.append(unicode);
}
else{
builder.append(c);
}
}
Log.i(TAG, builder.toString());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return builder.toString();
}
我嘗試添加笑臉,它給我的價值0xd83d
這是不是在下面的功能工作。
這裏是函數將Hexa值轉換爲表情符號,這個函數工作正常我試着提供手動的Hexa值。
// 0xd83d this value is get from above function but not work
// in this function
//String hexaCode = "0xd83d"; // not work
String hexaCode = "0x1F60A"; // work
int emoji= Integer.parseInt(hexaCode.substring(2), 16);
reurn new String(Character.toChars(emoji));
您能否讓我知道我做錯了什麼。請不要引用我任何表情符號庫。
我以爲你在問圖書館,請參考這裏的討論https://stackoverflow.com/questions/45453202/how-to-use-the-imagestored-image-of-device-with-text-on -textview,機器人 –