arun jagga
arun jagga

Reputation: 87

Send Message to specific user in twitter in android?

Hi I am getting the friend list from twitter now i want to tweet to particular user selected from the list. Any code snippet would be appreciated. Here is i am getting NullPointerException on twitter.sendmessage("id of user","msg")

private void tweet(){
    setTitle("Tweet");
    AlertDialog.Builder inputDialog;
    inputDialog = new AlertDialog.Builder(MainActivity.this);
    inputDialog.setTitle("Enter Tweet");
    et_input = new EditText(MainActivity.this);
    et_input.setWidth(250);
    et_input.setHeight(30);
    inputDialog.setView(et_input);
    inputDialog.setPositiveButton("Ok",
    new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            // TODO Auto-generated method stub
        txt_tweet= et_input.getText().toString();
        System.out.println("String what i have type "+txt_tweet);
            try{
               twitter.sendMessage("testsynapse1", txt_tweet);
                Toast.makeText(MainActivity.this,
                    "Tweet Successful", Toast.LENGTH_LONG).show();
            }
            catch (TwitterException e) {
                // TODO: handle exception
                e.getMessage();
            }
        }
    });
    inputDialog.setNegativeButton("Cancle",
    new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            // TODO Auto-generated method stub
        }
    });
    inputDialog.show();
}

Upvotes: 0

Views: 184

Answers (1)

Seshu Vinay
Seshu Vinay

Reputation: 13588

Do you know the username of particular user? If yes,

Then do like this:

String tweetToPost="@"+userName+"%20"+"your message"; 

postTweet(tweetToPost); 


public void postTweet(String str){
  String url="https://twitter.com/intent/tweet?text="+str.replace(" ","%20");

  WebView wv=new WebView(this);
        wv.loadUrl(url);
        setContentView(wv);
        wv.setWebViewClient(new WebViewClient(){

            @Override
            public void onPageFinished(WebView view, String url) {
                // TODO Auto-generated method stub
                super.onPageFinished(view, url);
            }


        });


}

I don't know if it works or not. But generally tweets to a specific user in Twitter are in the same format.

Upvotes: 1

Related Questions