我正在寻找一些方法来启动Twitter应用程序,并从我的应用程序打开一个指定的页面,没有webview.我在这里找到了Facebook的解决方案: 在指定的个人资料页面上打开Facebook应用
我需要类似的东西.
编辑 我刚刚找到了解决方案:
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]")));
}
Run Code Online (Sandbox Code Playgroud)
Har*_*rry 46
基于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);
Run Code Online (Sandbox Code Playgroud)
UPDATE
添加intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);以解决Twitter在我的应用程序中打开而不是作为新活动的问题.
小智 42
这对我有用: twitter://user?user_id=id_num
要知道ID:http://www.idfromuser.com/
通过2个步骤,使用Android使用其他应用打开Twitter应用上的页面:
1.只需粘贴以下代码(单击按钮或您需要的任何位置)
Intent intent = null;
try{
// Get Twitter app
this.getPackageManager().getPackageInfo("com.twitter.android", 0);
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("twitter://user?user_id=USER_ID"));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
} catch () {
// If no Twitter app found, open on browser
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://twitter.com/USERNAME"));
}
Run Code Online (Sandbox Code Playgroud)
2。intent = new Intent(Intent.ACTION_VIEW, Uri.parse("twitter://user?user_id=USER_ID"));
要获取USER_ID,只需输入用户名http://gettwitterid.com/并在其中获取Twitter用户ID
参考:https : //solutionspirit.com/open-page-twitter-application-android/
希望它会有所帮助:)
| 归档时间: |
|
| 查看次数: |
33082 次 |
| 最近记录: |