android - 我们如何在 android 中显示接收短信的笑脸

标签 android sms

我制作了一个 SMS 应用程序,它可以简单地执行发送和接收 SMS ...一切正常但是当我发送 smilays 或 emojis 它显示 emojis 代码而不是 emois 我使用 edittext 发送短信和 textview 接收短信我也改变了输入类型进入 longmessage 但仍然有同样的问题......我想在任何人发给我和我发给任何人时显示适当的表情...... 我的英语不好请不要介意

例如,当我选择默认的 android 表情符号时,我想向我的 friend 发送快乐的微笑,它会向我显示表情符号代码,例如 :) :( :P 不向我显示表情符号

private void SendSms() {
    // TODO Auto-generated method stub
    mPhoneNumber = FriendData.getNumber();
    mMessage=messagetosend.getText().toString();
    SmsManager smManager=SmsManager.getDefault();

    ArrayList<String> parts = smManager.divideMessage(mMessage);

    smManager.sendMultipartTextMessage(mPhoneNumber, null, parts, null, null);

    //String userInput = messagetosend.getText().toString();




    try
    {
    ContentValues values = new ContentValues(); 

        values.put("address", mPhoneNumber); 

        values.put("body", mMessage);
        values.put("date",  DateFormat.getDateTimeInstance().format(new Date()));
        getContentResolver().insert(Uri.parse("content://sms/sent"), values);
        Calendar c = Calendar.getInstance();
        SenderMessages(mMessage, c.getTimeInMillis());
        messagetosend.setText("");
         Toast.makeText(getApplicationContext(), " Message Sent", Toast.LENGTH_LONG).show();
    //  finish();

    }
    catch(Exception ex)
    {
      ex.printStackTrace();




     }

}


@Override
    public void onReceive(Context contx, Intent intent) {



        String body = "";
        String number = "";

        Bundle bundle = intent.getExtras();
        SmsMessage[] msgs = null;
        if (bundle != null) 
        {
            // ---retrieve the SMS message received---
            Object[] pdus = (Object[]) bundle.get("pdus");
            msgs = new SmsMessage[pdus.length];
            for (int i = 0; i < msgs.length; i++)
            {
                msgs[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
                body += msgs[i].getMessageBody().toString();
                number +=msgs[i].getOriginatingAddress();

            }
        }

        try
        {               
              Toast.makeText(contx, number, Toast.LENGTH_LONG).show();
              Toast.makeText(contx, body, Toast.LENGTH_LONG).show();

        }
        catch(Exception e)
        {
              Toast.makeText(contx, number, Toast.LENGTH_LONG).show();
              Toast.makeText(contx, body, Toast.LENGTH_LONG).show();
        }

    }

public void ReciverMessages(String message, long time){

    LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view  = inflater.inflate(R.layout.receiver_activity, null);
    mContainerView.addView(view);
    TextView texttime = (TextView) view.findViewById(R.id.time_date_receiver);
    TextView textmessage = (TextView) view.findViewById(R.id.tvreceiver);

    //DateFormat format = new DateFormat();

    SimpleDateFormat df = new SimpleDateFormat("dd-MM-yyyy");
    String MSGDate = df.format(time);
    if(MSGDate.equalsIgnoreCase(Utils.GetCurrentDate()))
    {
        SimpleDateFormat df1 = new SimpleDateFormat("HH:mm");
        String MSGDate1 = df1.format(time);
        texttime.setText(MSGDate1);
    }else
    {
        texttime.setText(MSGDate);
    }

    textmessage.setText(message);
}

最佳答案

我发现了一个非常有用的表情键盘。此键盘不使用 Unicode 序列,而只是使用本地镜像资源。我认为这种类型的键盘只能在此应用程序中使用,而不能用于其他应用程序或操作系统。

因此,我将包含 Assets 的 ImageView 替换为包含 Unicode 序列的 TextView。

在交叉引用 Supported Unicode Sequences 以及 Visual Unicode Database 之后,我意识到\u1F601 是 32 位 Unicode 表示,而 16 位表示可以设置如下:

EditText messageInput = (EditText) findViewById(R.id.message_input); messageInput.getText().append("\ud83d\ude01");

Implementations of Emoji (Emoticon) View/Keyboard Layouts

关于android - 我们如何在 android 中显示接收短信的笑脸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22278269/

相关文章:

asp.net - 从客户端检测到潜在的危险Request.Form值(textboxError ="<Responses><Response...")

sms - SMS网关如何工作?

c# - Twilio API - 发送短信时请求过多

java - ProgressBar(s)(水平)不显示(int)long的进度

android - 根据locale设置第三方activity的screenOrientation

java - Android:如何从工作线程到服务进行通信

android - 在某个事件发生后,如何通过我自己的应用程序打开和使用另一个 Android 应用程序?

java - Android 上的 TextToSpeech 初始化——如果失败怎么办?

java - 在 Jsoup 中解析 html

sms - 我需要一个 SIM 调制解调器,可以容纳 10-15 个普通 SIM 卡来接收和发送 SMS 消息