Search in sources :

Example 1 with LoginThread

use of com.lingtuan.firefly.xmpp.LoginThread in project SmartMesh_Android by SmartMeshFoundation.

the class XmppService method onStartCommand.

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    if (intent != null) {
        if (XmppAction.ACTION_LOGIN.equals(intent.getAction())) {
            // The login
            if (intent.getExtras() != null) {
                Bundle mBundle = intent.getExtras().getBundle(XmppAction.ACTION_LOGIN);
                String[] uNamePwd = mBundle.getStringArray(XmppAction.ACTION_LOGIN);
                String username = uNamePwd[0];
                String password = uNamePwd[1];
                if (!XmppUtils.isLogining) {
                    new LoginThread(mHandler, username, password).start();
                }
            }
        } else if (XmppAction.ACTION_LOGIN_MESSAGE_LISTENER.equals(intent.getAction())) {
            try {
                mXmppUtils = XmppUtils.getInstance();
                if (mPacketListener != null) {
                    mXmppUtils.getConnection().removePacketListener(mPacketListener);
                }
                mXmppUtils.sendOnLine();
                mPacketListener = new NextPacketListener();
                mXmppUtils.getConnection().addPacketListener(mPacketListener, new PacketFilter() {

                    @Override
                    public boolean accept(Packet packet) {
                        return true;
                    }
                });
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    return super.onStartCommand(intent, flags, startId);
}
Also used : Packet(org.jivesoftware.smack.packet.Packet) PacketFilter(org.jivesoftware.smack.filter.PacketFilter) Bundle(android.os.Bundle) LoginThread(com.lingtuan.firefly.xmpp.LoginThread)

Aggregations

Bundle (android.os.Bundle)1 LoginThread (com.lingtuan.firefly.xmpp.LoginThread)1 PacketFilter (org.jivesoftware.smack.filter.PacketFilter)1 Packet (org.jivesoftware.smack.packet.Packet)1