In android, we can able to post a status to twitter by using jtwitter. Its very simple to post a status in twitter. For that we need jtwitter.jar. you can download the jwitter.jar from here Post Status in Twitter Example :- Create a new android project, Add the below code in your AndroidManifest.xml for internet permission
Now we need to add Jtwitter to our project. Download the jwitter and save it in local drive. Click the Android Project –> Properties — > (In left Pane) Java Build Path — > Libraries In Libraries Tab click the ‘Add External Jars’ Button and then add the Jtwitter jar file. Edit your java file
01
packageorg.androidpeople.twitter;
02
03
importwinterwell.jtwitter.Twitter;
04
importwinterwell.jtwitter.TwitterException;
05
importandroid.app.Activity;
06
importandroid.os.Bundle;
07
importandroid.widget.Toast;
08
09
publicclassTwitterExample extendsActivity {
10
11
Twitter twitter;
12
13
@Override
14
publicvoidonCreate(Bundle savedInstanceState) {
15
super.onCreate(savedInstanceState);
16
setContentView(R.layout.main);
17
18
// Set your Twitter username / Password
19
twitter = newTwitter("username","password");
20
21
try
22
{
23
//Status to post in Twitter
24
twitter.setStatus("This is my first Tweet from Android - AndroidPeople.com");
25
Toast.makeText(TwitterExample.this, "Article Posted to Twitter Successfully!!", Toast.LENGTH_SHORT).show();
26
}
27
catch(TwitterException.E401 e)
28
{
29
// comes here when username or password is wrongs
30
Toast.makeText(TwitterExample.this, "Wrong Username or Password,Kindly Check your logins",Toast.LENGTH_SHORT).show();
31
}
32
catch(Exception e)
33
{
34
Toast.makeText(TwitterExample.this, "Network Host not responding",Toast.LENGTH_SHORT).show();
Android Post Status to Twitter using Jtwitter- Example
In android, we can able to post a status to twitter by using jtwitter. Its very simple to post a status in twitter. For that we need jtwitter.jar. you can download the jwitter.jar from herePost Sta