Reputation: 13511
As you may know, there's not a single organized documentation on how to properly login to Facebook using the asmack library. I've somehow managed to find some codes in the net to at least allow me to login to my account but why do I keep getting the following exception:
XMPPError connecting to chat.facebook.com:5222.: remote-server-error(502) XMPPError connecting to chat.facebook.com:5222. -- caused by: java.net.SocketException: Permission denied
Here's the code:
((Button) findViewById(R.id.login_btn)).setOnClickListener(
new OnClickListener() {
@Override
public void onClick(View v) {
ConnectionConfiguration config =
new ConnectionConfiguration("chat.facebook.com", 5222,
"chat.facebook.com");
config.setSASLAuthenticationEnabled(true);
Connection conn = new XMPPConnection(config);
try {
conn.connect();
SASLAuthentication.supportSASLMechanism("PLAIN", 0);
ProgressDialog loading = ProgressDialog.show(instance,
"", "Loading...");
conn.login(login_field.getText().toString(),
pwd_field.getText().toString(),
login_field.getText().toString() + "/fbchat");
loading.hide();
new AlertDialog.Builder(instance).setMessage(conn.getUser())
.create().show();
} catch (XMPPException e) {
new AlertDialog.Builder(instance).setMessage(e.toString())
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
})
.create().show();
}
}
});
Upvotes: 0
Views: 1748
Reputation: 5961
Obvious potential explanation - do you have the INTERNET
permission in your AndroidManifest.xml?
<uses-permission android:name="android.permission.INTERNET"/>
Without this, you will be unable to access network resources.
EDIT:
Where in the manifest are you requesting the INTERNET permission? It's location can make a difference, and it will fail silently. It needs to be at the top-level (under the <manifest>
tag, not attached to an activity, for example). Of course, if you added it via Eclipse, it's probably in the correct place already:
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.samplesync"
android:versionCode="1"
android:versionName="1.0">
<uses-permission android:name="android.permission.INTERNET" />
<activity>
...
</activity>
</manifest>
Alternatively, how are you connecting to the internet? This may also indicate that the required ports are being blocked by a firewall (see here)
Upvotes: 3