android - 从其他应用打开 Twitter 应用中的页面 - Android

标签 android twitter

我正在寻找某种方法来启动 Twitter 应用程序并从我的应用程序中打开指定页面,而无需 web View 。 我在这里找到了 Facebook 的解决方案: Opening facebook app on specified profile page

我需要类似的东西。

编辑 我刚刚找到了解决方案:

try {
    Intent intent = new Intent(Intent.ACTION_VIEW,
    Uri.parse("twitter://user?screen_name=[user_name]"));
    startActivity(intent);
} catch (Exception e) {
    startActivity(new Intent(Intent.ACTION_VIEW,
    Uri.parse("https://twitter.com/#!/[user_name]"))); 
}

最佳答案

根据 fg.radigales 的回答,如果可能的话,这就是我用来启动应用程序的方法,但否则会退回到浏览器:

Intent intent = null;
try {
    // get the Twitter app if possible
    this.getPackageManager().getPackageInfo("com.twitter.android", 0);
    intent = new Intent(Intent.ACTION_VIEW, Uri.parse("twitter://user?user_id=USERID"));
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
} catch (Exception e) {
    // no Twitter app, revert to browser
    intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://twitter.com/PROFILENAME"));
}
this.startActivity(intent);

更新

添加了 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 以解决 twitter 在我的应用程序中打开而不是作为新 Activity 打开的问题。

关于android - 从其他应用打开 Twitter 应用中的页面 - Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11105103/

相关文章:

Android:通过单击按钮增加和减少 textview 的 int 值

android - 支持的算法错误?

android - 自定义 View Canvas onDraw() 不绘制任何东西

java - android 录制语音时暂停选项

android - twitter4j 代码不适用于 ICS 和 JellyBean

python - Python twitter bot代码无效,redis-server端口

android - 保护 Android 上的 Twitter key

java - 启动屏幕后启动另一个 Activity 而不是主 Activity

python - Tweepy 对于大型 Twitter 帐户来说速度很慢

javascript - 通过 Javascript 访问 Twitter