【问题标题】:Open page in Facebook,Twitter and Google Plus app from other app - Android在 Facebook、Twitter 和 Google Plus 应用中从其他应用打开页面 - Android
【发布时间】:2012-07-04 21:09:43
【问题描述】:

我正在开发一个需要集成不同社交网络的社交功能的应用程序:Facebook、Twitter、Google+。

目前,在 Facebook 和 Twitter 中,如果用户有本地应用程序,我会被识别,如果有,我会打开它并向他展示我的粉丝页面。

对于 Twitter,我使用以下代码:

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]"))); 
    } 

对于 Facebook,下一个代码:

try{

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://profile/" + PROFILE_FACEBOOK_APP_ID));
startActivity(intent);

}catch(Exception e){

startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.facebook.com/UserNamePage")));
}

现在我想为 Google+ 做同样的事情。我看到我可以用下一个网址https://plus.google.com/MY_PAGE_ID/ 浏览到我的粉丝页面,但它一直问我是用 Google+ 应用程序还是用浏览器打开它,我希望他会用应用程序自动打开它,无需询问用户。

有没有简单的方法来做到这一点? 谢谢。

【问题讨论】:

    标签: android facebook twitter android-intent google-plus


    【解决方案1】:

    找到解决办法:

    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setClassName("com.google.android.apps.plus",
    "com.google.android.apps.plus.phone.UrlGatewayActivity");
    intent.putExtra("customAppUri", "FAN_PAGE_ID");
    startActivity(intent);
    

    【讨论】:

    • @Ovidiu Latcu 对于包名,您可以使用 PackageManager 获取正确的包名。
    • 他们可以更改额外的名称.. 随便什么。这不会举行。如果没有安装 G+,它也会崩溃。
    • @Ovidiu Latcu 检查是否安装了 G+ 应用程序,或者只是尝试捕获以避免崩溃并在您的途中处理异常。这个方法对我来说已经足够了,欢迎提出更好的方法。
    【解决方案2】:

    我觉得这样比较安全,因为我们不需要指定组件,只需要指定google+应用包名:

    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setData(Uri.parse("https://plus.google.com/[Google+ID]/"));
    intent.setPackage("com.google.android.apps.plus"); // don't open the browser, make sure it opens in Google+ app
    startActivity(intent);
    

    【讨论】:

      【解决方案3】:

      未知 google plus 是否需要 Intent 中的其他信息,但作为一般的 Android 解决方案,您可以显式设置目标。您将需要 google+ 的软件包名称。

      更多信息在这里:http://developer.android.com/reference/android/content/Intent.html#setPackage%28java.lang.String%29

      例如:

      Intent.setPackage("com.google.android.apps.plus"); //Don't know the exact package name
      

      【讨论】:

        猜你喜欢
        • 2012-06-21
        • 2013-02-11
        • 1970-01-01
        • 2014-10-07
        • 2011-06-16
        • 1970-01-01
        • 2011-10-17
        • 2014-08-22
        • 2011-10-15
        相关资源
        最近更新 更多