是否有像asmack一样的yahoo messenger集成库

时间:2013-01-18 18:24:42

标签: android yahoo-messenger

在android中是否有任何用于yahoo messenger集成的库

任何链接或代码都会对我有所帮助

先谢谢

1 个答案:

答案 0 :(得分:0)

有一个解决方案,我使用openymsg库,下面是我的代码

public class SimpleYahoo extends Activity implements SessionListener{
/** Called when the activity is first created. */

        private Session session = new Session();
        Button sendButton;
        boolean isLoginsuccess;
        ListView resultTextView;
        EditText editText;
        Handler handler;
        ArrayList<String> replymessage;
        String reply;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            // TODO Auto-generated method stub
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            replymessage=new ArrayList<String>();
             try {
                session.login("yahooid", "password");
            } catch (AccountLockedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IllegalStateException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (LoginRefusedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (FailedLoginException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
                session.addSessionListener(this);
            sendButton=(Button) findViewById(R.id.button);
            resultTextView=(ListView) findViewById(R.id.result);
            editText=(EditText) findViewById(R.id.input);
            sendButton.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    doLogin();
                }
            });
            handler=new Handler()
            {
                @Override
                public void handleMessage(Message msg) {
                    // TODO Auto-generated method stub
                    super.handleMessage(msg);
                    if(msg.what==0)
                    {
                        replymessage.add(reply);
                        setListAdapter();
                    }
                }
            };

        }



        private void doLogin() {
            try {



                session.sendMessage("targetyahooid", editText.getText().toString());

            } catch (Exception e) {
                Log.e(e.getMessage(), e.getMessage());

            }
        }





        @Override
        public void dispatch(FireEvent fe) {
            // TODO Auto-generated method stub
             ServiceType type = fe.getType();
                SessionEvent sessionEvent = fe.getEvent();

                if (type == ServiceType.MESSAGE) {
                    try {
                        // log request message
                        reply=sessionEvent.getMessage();
                        Log.i("message","message from " + sessionEvent.getFrom() + " \nmessage " + sessionEvent.getMessage() );

                        // give an automatic response
                   // session.sendMessage(sessionEvent.getFrom(), "hi, you are sending " + sessionEvent.getMessage());
                   // session.
                    handler.sendEmptyMessage(0);
                    } catch (Exception e) {
                        Log.e(e.getMessage(), e.getMessage());
                    }
                }

        }
        public void setListAdapter()
        {
            ArrayAdapter<String> arrayAdapter=new ArrayAdapter<String>(this,R.layout.multi_line_list_item,replymessage);
            resultTextView.setAdapter(arrayAdapter);
            resultTextView.setSelection(replymessage.size()-1);


        }

}

像魅力一样工作:)