Skip to content

Instantly share code, notes, and snippets.

@erfanegtfi
Last active May 9, 2020 07:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erfanegtfi/f41282b7cf2d2e740ca1fb88fa0d10ad to your computer and use it in GitHub Desktop.
Save erfanegtfi/f41282b7cf2d2e740ca1fb88fa0d10ad to your computer and use it in GitHub Desktop.
open on social network
public static void openInsagram(String channelName, Activity act) {
Uri uri = Uri.parse("http://instagram.com/_u/" + channelName);
Intent likeIng = new Intent(Intent.ACTION_VIEW, uri);
likeIng.setPackage("com.instagram.android");
try {
act.startActivity(likeIng);
} catch (ActivityNotFoundException e) {
act.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://instagram.com/" + channelName)));
}
}
public static void openTelegram(String channelName, Activity act) {
Intent telegram = new Intent(Intent.ACTION_VIEW, Uri.parse("tg://resolve?domain=" + channelName));
try {
act.startActivity(telegram);
} catch (ActivityNotFoundException ee) {
ee.printStackTrace();
telegram = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.telegram.me/"+channelName));
act.startActivity(telegram);
}
}
public static void openFacebook(String channelName, Activity act) {
String facebookPageID = ImageUtils.getFilename(channelName);
String facebookUrl = "https://www.facebook.com/" + facebookPageID;
String facebookUrlScheme = "fb://page/" + facebookPageID;
try {
int versionCode = act.getPackageManager().getPackageInfo("com.facebook.katana", 0).versionCode;
if (versionCode >= 3002850) {
Uri uri = Uri.parse("fb://facewebmodal/f?href=" + facebookUrl);
act.startActivity(new Intent(Intent.ACTION_VIEW, uri));
} else {
act.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(facebookUrlScheme)));
}
} catch (PackageManager.NameNotFoundException e) {
act.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(facebookUrl)));
}
}
public static void openGooglePlus(String channelName, Activity act) {
Intent telegram = new Intent(android.content.Intent.ACTION_SEND);
telegram.setData(Uri.parse(channelName));
telegram.setComponent(new ComponentName("com.google.android.apps.plus", "com.google.android.apps.plus.activity.UrlHandlerActivity"));
try {
act.startActivity(telegram);
} catch (ActivityNotFoundException e) {
e.printStackTrace();
try {
act.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(channelName)));
} catch (ActivityNotFoundException ee) {
ee.printStackTrace();
}
}
}
public static void openTwitter(String channelName, Activity act) {
Intent telegram = new Intent(android.content.Intent.ACTION_SEND);
telegram.setData(Uri.parse(channelName));
telegram.setComponent(new ComponentName("com.twitter.android", "com.twitter.android.activity.UrlHandlerActivity"));
try {
act.startActivity(telegram);
} catch (ActivityNotFoundException e) {
e.printStackTrace();
try {
act.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(channelName)));
} catch (ActivityNotFoundException ee) {
ee.printStackTrace();
}
}
}
public static void openPinterest(String channelName, Activity act) {
try {
act.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("pinterest://www.pinterest.com/" + channelName)));
} catch (Exception e) {
act.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.pinterest.com/" + channelName)));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment