2010-06-15 47 views
0

我想发送一条来自Android的推文。我已经执行了下面的代码。但我不打包发送任何推文。事实上,我创建的按钮不工作。任何人都可以打电话给我的概率?使用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 
     } 
    } 
} 

回答

0

我不能编辑您的帖子,所以我不得不把这个答案:你能提供有关该问题的更多细节?更确切地说,你的意思是“按钮不工作?”单击按钮时是否发生任何事情?如果什么都没有发生,可能是你碰到了ActivityNotFoundException。由于它被捕获,但没有采取行动,它是透明的。您是否尝试过调试,并在onClick方法上有一个断点?