AnsweredAssumed Answered

why using smack 4.1.0 no connection effect and no presence in spark? use jabber.web.id

Question asked by fanartics on Apr 28, 2015

It;s my first post - sorry for any wrong ....

 

I made smack 4.1.0 in asyntask - onpreexecute and onpostexceute i use toast message for knowing progress, but pass onpostexecute still not presence in spark 'friend list'

this some my code (using android studio), i;ve test by using gradle repositry n external libs

 

public void onClick(View v) {

        //click button

        new SmackConnection().execute();

    }

   

    private class SmackConnection extends AsyncTask<String,Void,String> {

        @Override

        protected void onPreExecute() {

            super.onPreExecute();

 

            Toast.makeText(getApplicationContext(), "Pre Execute ...",

                    Toast.LENGTH_SHORT).show();

 

        }

 

        @Override

        protected String doInBackground(String... params) {

            String varResult = "";

 

            try {

 

                XMPPTCPConnectionConfiguration.Builder builder = XMPPTCPConnectionConfiguration.builder();

 

                builder.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);

 

                builder.setUsernameAndPassword("eon_01@jabber.web.id", "eon_01");

                builder.setResource("test");

                builder.setServiceName("jabber.web.id");

                builder.setHost("jabber.web.id");

                builder.setPort(5222);

                builder.setConnectTimeout(10000);

                builder.setDebuggerEnabled(true);

               

                //SASLPlainMechanism saslPlainMechanism = new SASLPlainMechanism();

                //SASLAuthentication.registerSASLMechanism(saslPlainMechanism);

 

                AbstractXMPPConnection connection = new XMPPTCPConnection(builder.build());

 

                //saslPlainMechanism.instanceForAuthentication(connection);

 

                connection.connect();

                connection.login();

 

                ChatManager chatmanager = ChatManager.getInstanceFor(connection);

 

                // Create a new presence. Pass in false to indicate we're unavailable.

                Presence presence = new Presence(Presence.Type.available);

                presence.setStatus("I’m available brow");

                connection.sendPacket(presence);

 

 

                //Create chat

 

                Chat newChat = chatmanager.createChat("eon_02@jabber.web.id", new ChatMessageListener() {

 

                    @Override

 

                    public void processMessage(Chat chat, Message message) {

 

                        try {

 

                            chat.sendMessage(message);

 

                        } catch (SmackException.NotConnectedException e) {

 

 

                        }

 

                    }

 

                });

 

 

            } catch (SmackException | IOException | XMPPException e) {

 

                e.printStackTrace();

 

 

            }

 

 

            return varResult;

 

 

        } //doInBackground

 

        protected void onPostExecute(String result){

          

            Toast.makeText(getApplicationContext(), "final execute",

                    Toast.LENGTH_SHORT).show();

 

        }

 

 

    } //smackConnection async

 

 

There is no error when running in galaxy tab, but no connection effect or presence in 'spark'.

Outcomes