将yahoo messenger与android应用程序集成

时间:2012-11-02 09:04:23

标签: android yahoo-api yahoo-messenger

我在网上浏览找到一些代码片段或一些帮助在android应用程序中集成yahoo messenger。我找不到一些有用的东西。

请通过提供一些链接,教程或代码示例来帮助我,以便我可以集成雅虎信使。

由于

1 个答案:

答案 0 :(得分:1)

最后得到了yahoo messenger集成的解决方案我使用openymsg一个库并使用下面的链接

http://edwin.baculsoft.com/2011/11/creating-a-simple-yahoo-messenger-auto-response-with-java-and-openymsg-library/

在活动中更改了我的代码,如下所示,就像魅力一样:)

public class SimpleYahoo extends Activity implements SessionListener{
/** Called when the activity is first created. */
private Logger logger = Logger.getAnonymousLogger();
        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 {
                // insert your yahoo id
                // as for this example, im using my yahoo ID "dombaganas"



                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);


        }

}