Created
February 8, 2012 21:06
-
-
Save regisd/1773882 to your computer and use it in GitHub Desktop.
Intent to open the twitter client
This file contains hidden or 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
public Intent findTwitterClient() { | |
final String[] twitterApps = { | |
// package // name - nb installs (thousands) | |
"com.twitter.android", // official - 10 000 | |
"com.twidroid", // twidroyd - 5 000 | |
"com.handmark.tweetcaster", // Tweecaster - 5 000 | |
"com.thedeck.android" // TweetDeck - 5 000 }; | |
Intent tweetIntent = new Intent(); | |
tweetIntent.setType("text/plain"); | |
final PackageManager packageManager = getPackageManager(); | |
List<resolveinfo> list = packageManager.queryIntentActivities( | |
tweetIntent, PackageManager.MATCH_DEFAULT_ONLY); | |
for (int i = 0; i < twitterApps.length; i++) { | |
for (ResolveInfo resolveInfo : list) { | |
String p = resolveInfo.activityInfo.packageName; | |
if (p != null && p.startsWith(twitterApps[i])) { | |
tweetIntent.setPackage(p); | |
return tweetIntent; | |
} | |
} | |
} | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment