-1

Androidにyahooメッセンジャーを統合するためのライブラリはありますか

リンクやコードは私を大いに助けます

前もって感謝します

4

1 に答える 1

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


        }

}

魔法のように働きました:)

于 2013-01-18T18:32:34.560 に答える