通过Intent在Android中打开Goog​​le Plus页面

ben*_*fi7 21 android android-intent google-plus

我有一个Google Plus页面

https://plus.google.com/u/0/b/101839105638971401281/101839105638971401281/posts

和一个Android应用程序.我想在我的应用中打开此页面.我不想打开浏览器!

这将打开浏览器:

URL="https://plus.google.com/b/101839105638971401281/101839105638971401281/posts";
uri = Uri.parse(URL);
it = new Intent(Intent.ACTION_VIEW, uri);
startActivity(it);
Run Code Online (Sandbox Code Playgroud)

这次崩溃:

 Intent intent = new Intent(Intent.ACTION_VIEW);

intent.setClassName("com.google.android.apps.plus",             "com.google.android.apps.plus.phone.UrlGatewayActivity");

intent.putExtra("customAppUri", "10183910563897140128");
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)

提前致谢!

[解决了]

startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://plus.google.com/101839105638971401281/posts")));
Run Code Online (Sandbox Code Playgroud)

使用此解决方案,用户可以选择Google Plus APP或打开浏览器.如果选择APP,则不会发生崩溃.

Chi*_*hah 25

如果用户安装了Google+应用,您可以执行以下操作:

startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://plus.google.com/101839105638971401281/posts")));
Run Code Online (Sandbox Code Playgroud)

请注意URI的语法,并且它不包含/b/id/.


Har*_*ker 21

你必须首先检查用户是否已经在他/她的手机中有G + App?如果是,那么我们可以通过特定意图启动它,或者我们可以使用浏览器重定向到特定页面.

这是这种流程中的一种方法,

public void openGPlus(String profile) {
    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", profile);
        startActivity(intent);
    } catch(ActivityNotFoundException e) {
        startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://plus.google.com/"+profile+"/posts")));
    }
}
Run Code Online (Sandbox Code Playgroud)

现在你可以简单地调用这个方法,

//117004778634926368759 is my google plus id
openGPlus("117004778634926368759");
Run Code Online (Sandbox Code Playgroud)

扩展答案:您可以使用的Twitter和Facebook的方式相同,

对于Twitter,

public void openTwtr(String twtrName) {
        try {
           startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse("twitter://user?screen_name=" + twtrName)));
        } catch (ActivityNotFoundException e) {
           startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse("https://twitter.com/#!/" + twtrName)));
        }
}
Run Code Online (Sandbox Code Playgroud)

对于Facebook,

public void openFB(String facebookId) {
    try{
        String facebookScheme = "fb://profile/" + facebookId;
        Intent facebookIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(facebookScheme));
        startActivity(facebookIntent);
    } catch (ActivityNotFoundException e) {
        Intent facebookIntent = new Intent(Intent.ACTION_VIEW,Uri.parse("https://www.facebook.com/profile.php?id="+facebookId));
        startActivity(facebookIntent);
    }
}
Run Code Online (Sandbox Code Playgroud)

  • 将网关活动更改为:com.google.android.libraries.social.gateway.GatewayActivity (2认同)