Android Intent to launch Google+ app at Google+ Co

2019-05-01 06:25发布

问题:

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.

回答1:

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



回答2:

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.



回答3:

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.