Domanda

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.

È stato utile?

Soluzione

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 (?),

Altri suggerimenti

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.

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top