7

I found sample Facebook Chat Project for iOS here.

also i got the facebook chat doc here

Same way,

Did any one know facebook chat example app or way to implement fb chat in android?

Community
  • 1
  • 1
Ganapathy C
  • 5,835
  • 5
  • 39
  • 72

1 Answers1

9

There is one Android Open Source Project available : Beem Project and For connecting Facebook chat you can used following guidelines.

Steps for implementing Facebook chat API in Android:

  1. First we have to implement MemorizingTrustManager Library project in existing project.

    => For that you have to copy following three files in existing project

    • MemorizingTrustManager/src/de/duenndns/ssl/MTMDecision.java
    • MemorizingTrustManager/src/de/duenndns/ssl/MemorizingActivity.java
    • MemorizingTrustManager/src/de/duenndns/ssl/MemorizingTrustManager.java

    => And add following values in values/string.xml

    <resources>
        <string name="mtm_accept_cert">Accept Unknown Certificate?</string>
        <string name="mtm_decision_always">Always</string>
        <string name="mtm_decision_once">Once</string>
        <string name="mtm_decision_abort">Abort</string>
        <string name="mtm_notification">Certificate Verification</string>
    </resources>
    
  2. Second step, Instead of using SASLAuthentication such as X-FACEBOOK-PLATFORM, You can used following code to connect with Facebook and login using your Facebook Jabber ID (username@chat.facebook.com)

    public void connectToFb() throws XMPPException {
    
    ConnectionConfiguration config = new ConnectionConfiguration("chat.facebook.com", 5222);
    config.setSASLAuthenticationEnabled(true);
    config.setSecurityMode(SecurityMode.required);
    config.setRosterLoadedAtLogin(true);
    config.setTruststorePath("/system/etc/security/cacerts.bks");
    config.setTruststorePassword("changeit");
    config.setTruststoreType("bks");
    config.setSendPresence(false);
    try {
        SSLContext sc = SSLContext.getInstance("TLS");
        sc.init(null, MemorizingTrustManager.getInstanceList(this), new java.security.SecureRandom());
        config.setCustomSSLContext(sc);
    } catch (GeneralSecurityException e) {
        Log.w("TAG", "Unable to use MemorizingTrustManager", e);
    }
    XMPPConnection xmpp = new XMPPConnection(config);
    try {
        xmpp.connect();
        xmpp.login("facebookusername", "****"); // Here you have to used only facebookusername from facebookusername@chat.facebook.com
        Roster roster = xmpp.getRoster();
        Collection<RosterEntry> entries = roster.getEntries();
        System.out.println("Connected!");
        System.out.println("\n\n" + entries.size() + " buddy(ies):");
        // shows first time onliners---->
        String temp[] = new String[50];
        int i = 0;
        for (RosterEntry entry : entries) {
            String user = entry.getUser();
            Log.i("TAG", user);
        }
    } catch (XMPPException e) {
        xmpp.disconnect();
        e.printStackTrace();
    }
    }
    

At last, If you get all the Buddy list of your Facebook account in LogCat View, than you can implement simple Facebook chat using this tutorial.

Dipali
  • 354
  • 2
  • 5
  • 22
  • 1
    i have accepted the answer but till any other answer is there new answer is welcomed ;-) – Ganapathy C Jul 03 '12 at 08:34
  • I tried this method but it only returns a list of random numbers that seems to be in some way associated with my buddies? any idea? – Peter Jan 24 '13 at 19:26
  • @Dipali I m getting getAppKeyStore(/data/data/com.example.facebookchatdemo/app_KeyStore/KeyStore.bks) - file does not exist, How to resolve this. please help for Upvote :) – Qadir Hussain Jun 18 '13 at 08:27
  • Thanks alot....:) Would you please tell me , how to check presence of friends here? – Nizam Jul 18 '13 at 15:33
  • "For that you have to copy following three files in existing project", to where copy them???? – chaon Feb 16 '15 at 12:29