Open Google Plus Page Via Intent In Android

前端 未结 6 1259
情书的邮戳
情书的邮戳 2020-12-13 19:53

I have a Google Plus page

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

and an Android application.

6条回答
  •  半阙折子戏
    2020-12-13 20:41

    You have to first check that user already has G+ App in his/her phone or not ? If yes then we can start it by specific intent or we can use browser redirection to specific page.

    Here's one method in such flow,

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

    Now you can call this method simply like,

    //117004778634926368759 is my google plus id
    openGPlus("117004778634926368759");
    

    Extended Answer : Same way for twitter and facebook you can use,

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

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

提交回复
热议问题