简体   繁体   中英

Adding and checking the emoticon in the message text using smack Api - Android

I am working on chat application using smack api in android. How can i send the Emoticons in between or end of the text of message body using smack? And for received messages also how can i detect that text text has Emoticons some where in the text. I have referred this link http://www.igniterealtime.org/builds/smack/docs/latest/documentation/extensions/xhtml.html

Is this is only way or correct way of sending and receiving the Emoticons?

ISSUE 2: How can i detect that i had lost my connection XMPP server. Can any one had the Idea Please share your ideas

You can detect if the XMPP connection has lost using the following listener in Android

connection.addConnectionListener(new ConnectionListener() {
    @Override
    public void reconnectionSuccessful() {
        // TODO Auto-generated method stub
        System.out.println("ConnectionListener ==== >>>>> reconnectionSuccessful");
    }

    @Override
    public void reconnectionFailed(Exception arg0) {
        // TODO Auto-generated method stub
        System.out.println("ConnectionListener ==== >>>>> reconnectionFailed >>> " + arg0.toString());
    }

    @Override
    public void reconnectingIn(int arg0) {
        // TODO Auto-generated method stub
        System.out.println("ConnectionListener ==== >>>>> reconnectingIn >>> " + arg0);
    }

    @Override
    public void connectionClosedOnError(Exception arg0) {
        // TODO Auto-generated method stub
        System.out.println("ConnectionListener ==== >>>>> connectionClosedOnError >>>" + arg0.toString());

    }

    @Override
    public void connectionClosed() {
        // TODO Auto-generated method stub
        System.out.println("ConnectionListener ==== >>>>> connectionClosed");
    }
});

Use this library for emojicons:

https://github.com/rockerhieu/emojicon

remember to do Base64 encoding while you send packets over XMPP. Without Base64 encoding there are chances that the XMPP connection get loss all the time.

Happy coding !! :)

Your question depends on two main things;

  1. are all your users using your client?
  2. do you want to use a whole load of emoticons or just the standard ones?

If your users are all using your client you can implement it anyway you like. Another possible method would be to come up with character patterns to place in the message body that would be picked up by a regex pattern searcher, though this would get convoluted if you used more than a few emoticons.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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