Skip to content

Instantly share code, notes, and snippets.

@Karthik128
Created June 7, 2016 09:26
Show Gist options
  • Save Karthik128/238ec554676f72c1d644331ff72965bb to your computer and use it in GitHub Desktop.
Save Karthik128/238ec554676f72c1d644331ff72965bb to your computer and use it in GitHub Desktop.
public static Intent getOpenFacebookIntent(Context context) {
try {
context.getPackageManager()
.getPackageInfo("com.facebook.katana", 0); //Checks if FB is even installed.
return new Intent(Intent.ACTION_VIEW,
Uri.parse("fb://page/376227335860239")); //Trys to make intent with FB's URI
} catch (Exception e) {
return new Intent(Intent.ACTION_VIEW,
Uri.parse("https://www.facebook.com/karthikofficialpage")); //catches and opens a url to the desired page
}
}
public static Intent getOpenTwitterIntent(Context context) {
try {
context.getPackageManager()
.getPackageInfo("com.twitter.android", 0); //Checks if Twitter is even installed.
return new Intent(Intent.ACTION_VIEW,
Uri.parse("https://twitter.com/drkarthiik")); //Trys to make intent with Twitter's's URI
} catch (Exception e) {
return new Intent(Intent.ACTION_VIEW,
Uri.parse("https://twitter.com/drkarthiik")); //catches and opens a url to the desired page
}
}
public static Intent getOpenLinkdinIntent(Context context) {
try {
context.getPackageManager()
.getPackageInfo("com.linkedin.android", 0); //Checks if Linkdin is even installed.
return new Intent(Intent.ACTION_VIEW,
Uri.parse("https://www.linkedin.com/in/karthikm128")); //Trys to make intent with Linkdin's URI
} catch (Exception e) {
return new Intent(Intent.ACTION_VIEW,
Uri.parse("https://www.linkedin.com/in/karthikm128")); //catches and opens a url to the desired page
}
}
public static Intent getOpenGPlusIntent(Context context) {
try {
context.getPackageManager()
.getPackageInfo("com.google.android.apps.plus", 0); //Checks if G+ is even installed.
return new Intent(Intent.ACTION_VIEW,
Uri.parse("https://plus.google.com/u/0/+KarthikM128")); //Trys to make intent with G+'s URI
} catch (Exception e) {
return new Intent(Intent.ACTION_VIEW,
Uri.parse("https://plus.google.com/u/0/+KarthikM128")); //catches and opens a url to the desired page
}
}
public static Intent getOpenInstagramIntent(Context context) {
try {
context.getPackageManager()
.getPackageInfo("com.instagram.android", 0); //Checks if Instagram is even installed.
return new Intent(Intent.ACTION_VIEW,
Uri.parse("https://www.instagram.com/accounts/login/")); //Trys to make intent with Instagram's URI
} catch (Exception e) {
return new Intent(Intent.ACTION_VIEW,
Uri.parse("https://www.instagram.com/accounts/login/")); //catches and opens a url to the desired page
}
}
public static Intent getOpenYouTubeIntent(Context context) {
try {
context.getPackageManager()
.getPackageInfo("com.google.android.youtube", 0); //Checks if YT is even installed.
return new Intent(Intent.ACTION_VIEW,
Uri.parse("https://www.youtube.com/karthikm128")); //Trys to make intent with YT's URI
} catch (Exception e) {
return new Intent(Intent.ACTION_VIEW,
Uri.parse("https://www.youtube.com/karthikm128")); //catches and opens a url to the desired page
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment