Open Google Plus Page Via Intent In Android
Solution 1:
If the user has the Google+ app installed, you can do this:
startActivity(newIntent(Intent.ACTION_VIEW, Uri.parse("https://plus.google.com/101839105638971401281/posts")));
Notice the syntax of the URI, and that it doesn't contain /b/id/
.
Solution 2:
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,
publicvoidopenGPlus(String profile) {
try {
Intent intent = newIntent(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(newIntent(Intent.ACTION_VIEW, Uri.parse("https://plus.google.com/"+profile+"/posts")));
}
}
Now you can call this method simply like,
//117004778634926368759is my google plus id
openGPlus("117004778634926368759");
Extended Answer : Same way for twitter and facebook you can use,
For Twitter,
publicvoidopenTwtr(String twtrName) {
try {
startActivity(newIntent(Intent.ACTION_VIEW,Uri.parse("twitter://user?screen_name=" + twtrName)));
} catch (ActivityNotFoundException e) {
startActivity(newIntent(Intent.ACTION_VIEW,Uri.parse("https://twitter.com/#!/" + twtrName)));
}
}
And For Facebook,
publicvoidopenFB(String facebookId) {
try{
StringfacebookScheme="fb://profile/" + facebookId;
IntentfacebookIntent=newIntent(Intent.ACTION_VIEW, Uri.parse(facebookScheme));
startActivity(facebookIntent);
} catch (ActivityNotFoundException e) {
IntentfacebookIntent=newIntent(Intent.ACTION_VIEW,Uri.parse("https://www.facebook.com/profile.php?id="+facebookId));
startActivity(facebookIntent);
}
}
Solution 3:
/**
* 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.
*/publicstatic 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;
}
Solution 4:
What does the stack trace say when it crashes?
Also I'm not sure if this would make a difference but there's a typo in the ID. You wrote:
intent.putExtra("customAppUri", "10183910563897140128");
but originally the ID was 101839105638971401281
. You left off the 1 at the end.
Solution 5:
Why not just Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
. Android OS queries all Applications that can handle a specific Uri. Google+, as an app, is programmed to be able to handle the Uri you are requesting. So it will show up as an option in a chooser (or just go to it if the user has already selected the Google+ app to be default for that Uri.
Post a Comment for "Open Google Plus Page Via Intent In Android"