5

There is already a good SO question for displaying a Google+ Page in the Google+ Android app:

Open Google Plus Page Via Intent In Android

But what about the Intent to launch the Google+ app at a specific Google+ Community?

EDIT - to the silent down-voters, please explain why you down-voted.

Community
  • 1
  • 1
Mark
  • 7,446
  • 5
  • 55
  • 75

3 Answers3

6

My solution, working with G+ version "5.3.0.91034052", tested today

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

It's not bullet proof, you need Google+ app on your device, in case you don't have it some kind of try-catch might be nice (?),

outlying
  • 578
  • 1
  • 8
  • 19
  • 2
    Instead try-catch you can resolve intent ```if (sendIntent.resolveActivity(getPackageManager()) != null) { startActivity(sendIntent); }``` – Damian Petla Apr 29 '15 at 06:10
  • 1
    You can remove the "/u/0" part from the Uri – Mark May 17 '15 at 09:55
  • 1
    Thanks for both comments, for future readers (with similar problem) don't use "setClassName" in your intents, in case of G+ application that was the issue, Google devs changed class namespace and class name. Instead stick to "setPackage" which indicates applicationId and you cannot change this one on Google Play once app is uploaded there. – outlying May 19 '15 at 13:23
  • Better still: `if (intent.resolveActivity(getPackageManager()) == null) { intent.setPackage(null); if (intent.resolveActivity(getPackageManager()) == null) { intent = null; } } if (intent != null) { startActivity( intent ); }` – Mark May 21 '15 at 13:35
4

I achieved this by using:

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

Where 123456789 is the id of the community copied from the address bar.

0

Just in case anyone else needs to do this I had to do this in my app and used the below code

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

Where 1234356789 is the community id from the address bar.

This then prompts whether you want to open with Google+ or browser.

davidhodges86
  • 301
  • 2
  • 5