Stack Overflow archive
3 score

Open Google Plus Page Via Intent In Android

score
3
question views
13.9K
license
CC BY-SA 3.0
java
/**
 * Intent to open the official Google+ app to the user's profile. If the Google+ app is not
 * installed then the Web Browser will be used.
 * 
 * </br></br>Example usage:</br>
 * <code>newGooglePlusIntent(context.getPackageManager(), "https://plus.google.com/+JaredRummler");</code>
 * 
 * @param pm
 *            The {@link PackageManager}.
 * @param url
 *            The URL to the user's Google+ profile.
 * @return The intent to open the Google+ app to the user's profile.
 */
public static Intent newGooglePlusIntent(PackageManager pm, String url) {
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    try {
        if (pm.getPackageInfo("com.google.android.apps.plus", 0) != null) {
            intent.setPackage("com.google.android.apps.plus");
        }
    } catch (NameNotFoundException e) {
    }
    return intent;
}

Originally posted on Stack Overflow. Public user contributions are licensed under Creative Commons Attribution-ShareAlike.