Skip to content

Instantly share code, notes, and snippets.

@sabadow
Created February 9, 2012 09:12
Show Gist options
  • Save sabadow/1778654 to your computer and use it in GitHub Desktop.
Save sabadow/1778654 to your computer and use it in GitHub Desktop.
Launch Twitter official client from Android through an Intent
Intent tweetIntent = new Intent(Intent.ACTION_SEND);
tweetIntent.putExtra(Intent.EXTRA_TEXT, "This is a Test.");
tweetIntent.setType("text/plain");
PackageManager packManager = getPackageManager();
List<ResolveInfo> resolvedInfoList = packManager.
queryIntentActivities(tweetIntent, PackageManager.MATCH_DEFAULT_ONLY);
boolean resolved = false;
for(ResolveInfo resolveInfo: resolvedInfoList){
if(resolveInfo.activityInfo.packageName.startsWith("com.twitter.android")){
tweetIntent.setClassName(resolveInfo.activityInfo.packageName,
resolveInfo.activityInfo.name);
resolved = true;
break;
}
}
if(resolved)
startActivity(tweetIntent);
else
Toast.makeText(this, "Twitter isn't found on your system", Toast.LENGTH_LONG).show();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment