3

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

请通过提供一些链接、教程或代码示例来帮助我,以便我可以集成 yahoo messenger。

谢谢

4

1 回答 1

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


        }

}

于 2013-01-18T18:15:51.953 回答