gpt4 book ai didi

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

转载 作者:IT老高 更新时间:2023-10-28 13:14:42 30 4
gpt4 key购买 nike

我正在寻找某种方法来启动 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/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com