Hi Flow,
I passed 1 week trying to understand this sentence in the README:
"In order to work correctly on Android, you need to register Smack’s
XMPP Providers and Extensions manually and init some static code
blocks before you doing any XMPP activty. Calling
SmackAndroid.init(Context) (in org.jivesoftware.smack) will do this
for you."
But really it is difficult for me. Could you please help with a step by step TUTORIAL so that we could understand?
What do you call context ? Are you refering to the Context of a main class activity ?
The truth is that if you could give a simple working example I would be really greatful.
Here is my code but I think I’m not getting it:
############################################
public class MainActivity extends Activity {
public final static String EXTRA_MESSAGE = “com.example.rasaxe.MESSAGE”;
private static Context context;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
context = getApplicationContext();
}
/*public static Context getAppContext() {
return context;
}*/
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
/** Called when the user clicks the Send button */
public void sendMessage(View view) {
// Do something in response to button
Intent intent = new Intent(this, DisplayMessageActivity.class);
EditText editText = (EditText) findViewById(R.id.edit_message);
String message = editText.getText().toString();
intent.putExtra(EXTRA_MESSAGE, message);
SmackAndroid.init(context);
/*AndroidConnectionConfiguration config = null;
try {
config = new AndroidConnectionConfiguration(“jabber.org”, 5222);
} catch (XMPPException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Connection.DEBUG_ENABLED = true;
Connection conn2 = new XMPPConnection(config);
try {
conn2.connect();
conn2.login(“rasaxe”, “Tahranovitch1”);
} catch (XMPPException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}*/
startActivity(intent);
}
}
################################
Regards,
Tarik