从Android应用程序打开Twitter应用程序用户配置

Bap*_*sta 14 twitter android

我能够启动Twitter应用程序(如果它存在于手机上),但我找不到如何自动显示特定的用户配置文件.

这样的内容适用于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");
Run Code Online (Sandbox Code Playgroud)

这是Facebook的方式:

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://profile/USER_ID"));
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)

当我启动Twitter应用程序时应该有相同类型的解决方案?

Intent intent = getPackageManager().getLaunchIntentForPackage("com.twitter.android");
intent.putExtra("WHAT_TO_PUT_HERE?", "USER_ID");
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)

Chr*_*han 29

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)));
}
Run Code Online (Sandbox Code Playgroud)

这与新的Twitter应用程序一起工作正常.@Baptiste Costa提供的解决方案对我不起作用.


Bap*_*sta 17

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")));
}
Run Code Online (Sandbox Code Playgroud)