Tweeting using twitter for android intent

Well am working on this application where I want to be able to posts tweets using the native android application.  Here is the how to.

launch the twitter PostActivity directly by getting the ActivityInfo instance of it. This is done by scanning through the activities returned by the Intent.ACTION_SEND and looking for “”.

This is a not a clean way of doing it since we are searching for a particular hard coded activity. The best way is to just let the user select from the dialog box returned by Intent.ACTION_SEND.

Context context = getApplication();
String message = "Testing integration into native twitter android app :)";
message = "It works!";
try {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT, message);
final PackageManager pm = context.getPackageManager();
final List activityList = pm.queryIntentActivities(intent, 0);
int len = activityList.size();
for (int i = 0; i < len; i++) {
final ResolveInfo app = (ResolveInfo) activityList.get(i);
if (""
.equals( {
final ActivityInfo activity = app.activityInfo;
final ComponentName name = new ComponentName(
intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT, message);
} catch (final ActivityNotFoundException e) {
Toast.makeText(this, "Damn! no suitable Twitter apps found.",
Toast.LENGTH_SHORT) .show();

Happy Coding.


One thought on “Tweeting using twitter for android intent

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s