Open Twitter application user profile from Android application
12,114
Solution 1
try {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("twitter://user?screen_name=" + twitter_user_name)));
}catch (Exception e) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://twitter.com/#!/" + twitter_user_name)));
}
This is working fine with the new Twitter app. Solution provided by @Baptiste Costa didn't work for me.
Solution 2
try
{
// Check if the Twitter app is installed on the phone.
getPackageManager().getPackageInfo("com.twitter.android", 0);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setClassName("com.twitter.android", "com.twitter.android.ProfileActivity");
// Don't forget to put the "L" at the end of the id.
intent.putExtra("user_id", 01234567L);
startActivity(intent);
}
catch (NameNotFoundException e)
{
// If Twitter app is not installed, start browser.
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://twitter.com/AndroTesteur")));
}
Solution 3
This is a very old question, I would like to shed some light into it. I have done it using either the user id or the username if that fails.
Intent intent;
try {
// Check if the Twitter app is installed on the phone.
context.getPackageManager().getPackageInfo("com.twitter.android", 0);
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("twitter://user?user_id=813679215195410432"));
} catch (Exception e) {
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://twitter.com/LynxMods"));
}
context.startActivity(intent);
Related videos on Youtube
Author by
Baptiste Costa
Updated on September 15, 2022Comments
-
Baptiste Costa almost 2 years
I'm able to start Twitter application (if it exists on the phone), yet I can't find how to automatically display a specific user profile.
Something like this works for Google+:
Intent intent = new Intent(Intent.ACTION_VIEW); intent.setClassName("com.google.android.apps.plus", "com.google.android.apps.plus.phone.UrlGatewayActivity"); intent.putExtra("customAppUri", "USER_ID");
Here is the Facebook way:
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://profile/USER_ID")); startActivity(intent);
There should be the same kind of solution when I start Twitter app ?
Intent intent = getPackageManager().getLaunchIntentForPackage("com.twitter.android"); intent.putExtra("WHAT_TO_PUT_HERE?", "USER_ID"); startActivity(intent);
-
735 over 9 yearsthis's worked on emulator which run into catch. And also worked well on my device which installed twitter app after I change user_id to screen_name, intentTW.putExtra("screen_name", twitterProfile);