【问题标题】:Android Intent to launch Google+ app at Google+ Community screenAndroid 打算在 Google+ 社区屏幕上启动 Google+ 应用程序
【发布时间】:2014-04-15 06:08:03
【问题描述】:

关于在 Google+ Android 应用中显示 Google+ 信息页已经有一个很好的 SO 问题:

Open Google Plus Page Via Intent In Android

但是在特定的 Google+ 社区启动 Google+ 应用的意图呢?

编辑 - 对沉默的投反对票的人,请解释你投反对票的原因。

【问题讨论】:

  • 您找到真正的解决方案了吗?不确定接受的答案是否有效,但它不再有效。反正很糟糕……
  • @JacekKwiecień 我已经接受了另一个答案

标签: android android-intent google-plus


【解决方案1】:

我的解决方案,使用 G+ 版本“5.3.0.91034052”,今天测试

final Intent intent = new Intent( Intent.ACTION_VIEW, Uri.parse( "https://plus.google.com/communities/107847486351510098159" ) );
intent.setPackage( "com.google.android.apps.plus" );
if (intent.resolveActivity(getPackageManager()) != null) { 
    startActivity( intent );
}

这不是防弹的,你需要在你的设备上安装 Google+ 应用,以防万一你没有它,某种 try-catch 可能会很好 (?),

【讨论】:

  • 代替 try-catch 你可以解决意图if (sendIntent.resolveActivity(getPackageManager()) != null) { startActivity(sendIntent); }
  • 您可以从 Uri 中删除“/u/0”部分
  • 感谢两位 cmets,对于未来的读者(有类似问题)不要在您的意图中使用“setClassName”,如果 G+ 应用程序出现问题,Google 开发人员更改了类命名空间和类名.而是坚持使用表示 applicationId 的“setPackage”,一旦应用上传到 Google Play,您就无法在 Google Play 上更改它。
  • 更好的是:if (intent.resolveActivity(getPackageManager()) == null) { intent.setPackage(null); if (intent.resolveActivity(getPackageManager()) == null) { intent = null; } } if (intent != null) { startActivity( intent ); }
【解决方案2】:

我通过以下方式实现了这一点:

String communityPage = "communities/123456789";
    try {
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setClassName("com.google.android.apps.plus",
                "com.google.android.apps.plus.phone.UrlGatewayActivity");
        intent.putExtra("customAppUri", communityPage);
        startActivity(intent);
        } catch(ActivityNotFoundException e) {
            // fallback if G+ app is not installed
            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://plus.google.com/"+communityPage)));
        }

其中 123456789 是从地址栏中复制的社区 ID。

【讨论】:

  • 看起来此活动未在新的 Google+ 应用中声明。这段代码过去可以正常工作。
【解决方案3】:

以防万一其他人需要这样做,我必须在我的应用程序中这样做并使用以下代码

startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://plus.google.com/communities/1234356789")));

其中 1234356789 是地址栏中的社区 ID。

然后会提示您是要使用 Google+ 还是浏览器打开。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-01-03
    • 2011-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多