Created
February 9, 2012 09:12
-
-
Save sabadow/1778654 to your computer and use it in GitHub Desktop.
Launch Twitter official client from Android through an Intent
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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