Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open Twitter application user profile from Android application

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);
like image 308
Baptiste Costa Avatar asked Aug 20 '12 11:08

Baptiste Costa


People also ask

How do I open Twitter in app instead of browser?

Click on the Apps and select Manage Apps. Now, click on the three-dots menu at the top and choose Default Apps. Scroll down, and click on Opening Links. Tap on the app for which you want to links to open in-app instead of browser.

Can Android users use Twitter?

The Twitter for Android app is available for phones running Android OS versions 7.93. 4 and above. Note: We no longer support older versions of Twitter for Android. To experience the most up-to-date Twitter for Android experience, download the latest version in the store or visit twitter.com in your browser.

How do you get Twitter to work on Android?

Open the Google Play app or another app store that features the Twitter for Android app. Search for Twitter for Android. Select Download and accept the permissions. Once the Twitter for Android app finishes downloading, open the app and sign in.


2 Answers

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.

like image 169
Chrishan Avatar answered Sep 19 '22 16:09

Chrishan


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")));
}
like image 23
Baptiste Costa Avatar answered Sep 21 '22 16:09

Baptiste Costa