I have decided to try out integrating Twitter into an Android application. It appears that this takes a little bit of more effort than for Facebook. There is no official SDK for this, so you are pretty much on your own. There are lots of unofficial plugins like Twitter4J but I could not find one that would be simple to implement and would look nice. In the end, after hours of Googling and testing different solutions I decided for the simplest solution there is. It’s not the best one, mind you, but it’s simple and efficient. You do not need to get your own api key and its only a few lines of code. The solution is launching the web browser with some parameters, one of them is the string that will be tweeted.

public void twitterAction()
	{
		String yourTweet="This is your tweet!";
		String url = "https://twitter.com/intent/tweet?text="+yourTweet+" %2simple";
	    Intent i = new Intent(Intent.ACTION_VIEW);
	    Uri u = Uri.parse(url);
	    try
	    {
	    	i.setData(u);
	    	startActivity(i);
	    }
	    catch(ActivityNotFoundException ex)
	    {
	    	Toast.makeText(getActivity(), "No browser installed", Toast.LENGTH_SHORT).show();
	    }
	}

After calling this method, your browser will be opened and you will have to login. Afterwards your message will be tweeted along with a hashtag. If there is no browser present an exception is caught and displayed with a toast message. Simple and nice :).