使用Android发送推文

时间:2010-06-15 04:54:09

标签: android twitter

我想从Android发送一条推文。我已经执行了以下代码。但我发送任何推文并不是很麻烦。我创建的按钮根本不起作用。任何人都可以打电话给我吗?

这是我的代码..

import android.app.Activity;

import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.os.Bundle;

public class TwidgitPublicIntent extends Activity implements OnClickListener {

    private static final int TWIDGIT_REQUEST_CODE = 2564;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        ((Button)findViewById(R.id.tweet_button)).setOnClickListener(this);
        ((Button)findViewById(R.id.mention_button)).setOnClickListener(this);
        ((Button)findViewById(R.id.retweet_button)).setOnClickListener(this);
        ((Button)findViewById(R.id.message_button)).setOnClickListener(this);
    }
    public void onClick(View v) {
        switch(v.getId()) {
            case R.id.tweet_button:

                // Standard tweet
                Intent tIntent = new Intent("com.disretrospect.twidgit.TWEET");
                tIntent.putExtra("com.disretrospect.twidgit.extras.MESSAGE", "_message_in_here_");
                try {
                    this.startActivityForResult(tIntent, TWIDGIT_REQUEST_CODE);
                } catch (ActivityNotFoundException e) {
                    // If Twidgit is not installed
                }

                break;
            case R.id.mention_button:

                // Mention
                Intent mIntent = new Intent("com.disretrospect.twidgit.MENTION");
                mIntent.putExtra("com.disretrospect.twidgit.extras.TO", "_username_to_xmention_");
                mIntent.putExtra("com.disretrospect.twidgit.extras.MESSAGE", "_message_in_here_");
                try {
                    this.startActivityForResult(mIntent, TWIDGIT_REQUEST_CODE);
                } catch (ActivityNotFoundException e) {
                    // If Twidgit is not installed
                }

                break;
            case R.id.retweet_button:

                // Retweet a tweet
                Intent rtIntent = new Intent("com.disretrospect.twidgit.RETWEET");
                rtIntent.putExtra("com.disretrospect.twidgit.extras.MESSAGE", "_message_in_here_");
                rtIntent.putExtra("com.disretrospect.twidgit.extras.VIA", "_original_author_of_tweet_name_");
                try {
                    this.startActivityForResult(rtIntent, TWIDGIT_REQUEST_CODE);
                } catch (ActivityNotFoundException e) {
                    // If Twidgit is not installed
                }

                break;
            case R.id.message_button:

                // Send DM
                Intent dmIntent = new Intent("com.disretrospect.twidgit.DIRECT_MESSAGE");
                dmIntent.putExtra("com.disretrospect.twidgit.extras.TO", "_username_to_send_dm_to_");
                dmIntent.putExtra("com.disretrospect.twidgit.extras.MESSAGE", "_message_in_here_");
                try {
                    this.startActivityForResult(dmIntent, TWIDGIT_REQUEST_CODE);
                } catch (ActivityNotFoundException e) {
                    // If Twidgit is not installed
                }

                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        // Check result code
        if(resultCode == Activity.RESULT_OK) {
            // Check requestCode
            switch(requestCode) {
                case TWIDGIT_REQUEST_CODE:
                    // Handle successful return
                break;
            }
        } else if(resultCode == Activity.RESULT_CANCELED){
            // Handle canceled activity
        }
    }
}

1 个答案:

答案 0 :(得分:0)

我无法编辑你的帖子所以我必须回答这个问题:你能否提供有关问题的更多细节?更准确地说,“按钮不起作用是什么意思?”当你点击按钮时发生了什么事吗?如果没有任何反应,可能是您遇到了ActivityNotFoundException。由于它被捕获,但没有采取任何行动,它是透明的。您是否尝试过onClick方法的断点?