Muhammad Ahmad
Muhammad Ahmad

Reputation: 541

how we show smilays on receiving sms in android

I make an SMS app which simple perform sending and receiving SMS ... everything is ok but when i send smilays or emojis it display emojis code not emois i used edittext for sending sms and textview for receiving sms i also changed input type into longmessage but still have the same issue ... I want to show proper smilays when anyone send me and when i send anyone .... my english is not good plz dont mind

for example i want to send happy smile to my friend when i pick default android emojis its show me emojis code like :) :( :P not show me the emojis

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);
}

Upvotes: 2

Views: 795

Answers (1)

Muhammad Ahmad
Muhammad Ahmad

Reputation: 541

I found a very useful Emoticon Keyboard. This keyboard is not using Unicode sequences but rather just local image assets. I am thinking that this type of keyboard can only be useful within this app and not with other apps or Operating Systems.

So instead I am replacing the ImageView containing an asset with a TextView containing a Unicode sequence.

After cross referencing Supported Unicode Sequences as well as the Visual Unicode Database I realized that \u1F601 was a 32 bit Unicode representation, and the 16bit representation can be set like :

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

Implementations of Emoji (Emoticon) View/Keyboard Layouts

Upvotes: 1

Related Questions