1
0
Fork 0
mirror of https://github.com/ethauvin/android-about-box.git synced 2025-04-25 02:37:11 -07:00

Added correct error handling when facebook/twitter is not installed. (Close #8)

This commit is contained in:
Alex Dibrivnyi 2017-02-09 20:41:49 +02:00
parent 685b6e6ffe
commit ed10e03d6b

View file

@ -221,27 +221,36 @@ public class AboutActivity extends MaterialAboutActivity {
}
public static void getOpenFacebookIntent(Activity context, String name) {
Intent intent;
try {
context.getPackageManager().getPackageInfo("com.facebook.katana", 0);
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://profile/" + name));
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://profile/" + name));
context.startActivity(intent);
} catch (Exception e) {
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/" + name));
try {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/" + name));
context.startActivity(intent);
} catch (Exception e1) {
Toast.makeText(context, R.string.can_not_open, Toast.LENGTH_SHORT).show();
}
}
context.startActivity(intent);
}
public static void startTwitter(Activity context, String name) {
Intent intent;
try {
context.getPackageManager().getPackageInfo("com.twitter.android", 0);
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("twitter://user?screen_name=" + name));
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("twitter://user?screen_name=" + name));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
} catch (Exception e) {
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://twitter.com/" + name));
try {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://twitter.com/" + name));
context.startActivity(intent);
} catch (Exception e1) {
Toast.makeText(context, R.string.can_not_open, Toast.LENGTH_SHORT).show();
}
}
context.startActivity(intent);
}
public void openApp(String packageName, boolean googlePlay) {//true if Google Play, false if Amazon Store