Facebook messenger app using asmack android xmpp

399 views Asked by At

I was trying to fetch facebook friends and send message using asmack library over XMPP.I took reference from this site for facebook messaging.But after executing the code below i got exception.

public class MyActivity extends Activity {
public int state = 0;
private static final String TAG = "MyActivity"; 

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);       

    new Thread(new Runnable() {
      public void run() {            
        //XMPPConnection xmpp = new XMPPConnection("jabber.iitsp.com");
        XMPPConnection xmpp = new XMPPConnection("chat.facebook.com");
        try {
          xmpp.connect();

          // for other jabber accounts, truncate after the @
          //xmpp.login("username", "password"); 

          // for gtalk / gmail, include the @
          xmpp.login("[email protected]", "your-fb-password");

        } catch (XMPPException e) {
          Log.v(TAG, "Failed to connect to " + xmpp.getHost());
          e.printStackTrace();
        }
        ChatManager chatmanager = xmpp.getChatManager();
        Chat newChat = chatmanager.createChat("[email protected]", new MessageListener() {
          // THIS CODE NEVER GETS CALLED FOR SOME REASON
          public void processMessage(Chat chat, Message message) {
            try {
              Log.v(TAG, "Got:" + message.getBody());
              chat.sendMessage(message.getBody());
            } catch (XMPPException e) {
              Log.v(TAG, "Couldn't respond:" + e);
            }
            Log.v(TAG, message.toString());
          }
        });

        // Send something to [email protected]
        try {
          newChat.sendMessage("my message");
        } catch (XMPPException e) {
          Log.v(TAG, "couldn't send:" + e.toString());
        }

        // Accept only messages from [email protected]
        PacketFilter filter 
            = new AndFilter(new PacketTypeFilter(Message.class), 
                            new FromContainsFilter("[email protected]"));

        // Collect these messages
        PacketCollector collector = xmpp.createPacketCollector(filter);

        while(true) {
          Packet packet = collector.nextResult();

          if (packet instanceof Message) {
            Message msg = (Message) packet;
            // Process message
            Log.v(TAG, "Got message:" + msg.getBody());
          }
        }

      }

    }).start();

    //setContentView(this);
}}

I got following errors during execution of the code:-

1) java.security.KeyStoreException: java.security.NoSuchAlgorithmException: KeyStore jks implementation not found


2) SASL authentication failed using mechanism PLAIN: 

Then my program crashed

java.lang.IllegalStateException: Not connected to server.

Any help would be appreciated.

0

There are 0 answers