在Android中通过Intent打开Google Plus页面

在Android中通过Intent打开Google Plus页面,android,android-intent,google-plus,Android,Android Intent,Google Plus,我有一个googleplus页面 还有一个Android应用程序我想在我的应用程序中打开此页面。我不想打开浏览器 这将打开浏览器: URL="https://plus.google.com/b/101839105638971401281/101839105638971401281/posts"; uri = Uri.parse(URL); it = new Intent(Intent.ACTION_VIEW, uri); startActivity(it); 这导致: Intent int

我有一个
googleplus
页面

还有一个Android应用程序我想在我的应用程序中打开此页面。我不想打开浏览器

这将打开浏览器:

URL="https://plus.google.com/b/101839105638971401281/101839105638971401281/posts";
uri = Uri.parse(URL);
it = new Intent(Intent.ACTION_VIEW, uri);
startActivity(it);
这导致:

 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);
提前谢谢

[已解决]

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

使用此解决方案,用户可以选择Google Plus应用程序或打开浏览器。如果选择应用程序,则不会崩溃。

堆栈跟踪在崩溃时会显示什么

此外,我不确定这是否会带来不同,但ID中有一个输入错误。您写道:

intent.putExtra("customAppUri", "10183910563897140128");

但最初ID是
101839105638971401281
。您在结尾处省略了1。

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

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

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

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

在这种流程中有一种方法

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")));
    }
}
现在你可以简单地调用这个方法

//117004778634926368759 is my google plus id
openGPlus("117004778634926368759");
扩展答案对于twitter和facebook,您可以使用相同的方式

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)));
        }
}
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);
    }
}
用于推特

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)));
        }
}
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);
    }
}
而对于Facebook

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

为什么不干脆
Intent Intent=newintent(Intent.ACTION_视图,Uri.parse(url));

。Android操作系统查询所有可以处理特定Uri的应用程序。Google+作为一个应用程序,被编程为能够处理您请求的Uri。因此,它将在选择器中显示为一个选项(或者,如果用户已经选择Google+应用程序作为该Uri的默认设置,则直接访问该应用程序。

在应用程序中嵌入网络视图并加载页面如何?为此,我更喜欢直接打开浏览器。Google+社区如何?现在它变成了com.Google.android.libraries.social.gateway.gateway活动更改网关活动访问:com.google.android.libraries.social.gateway.gatewayActivity关于“com.google.android.apps.plus.phone.UrlGatewayActivity”,您不应假设这是活动的路径。相反,请通过调用QueryInputActivities仅使用packageName,然后检查其中哪些与应用程序的packageName匹配。对于fb:web intent的url应更改为“对于facebook应用程序版本11+intent,请参阅Jareds的答案。url:fb://facewebmodal/f?href=[正常\u FACEBOOK\u页面\u URL]
public void openTwitter(String twitterName) {
    try {
       startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse("twitter://user?screen_name=" + twitterName)));
    } catch (ActivityNotFoundException e) {
       startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse("https://twitter.com/#!/" + twitterName)));
    }
}