Open Twitter application user profile from Android application

Viewed 12371

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);
3 Answers

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