From ed10e03d6b5f00c8dd11aa00178bcfd3a2ee452c Mon Sep 17 00:00:00 2001 From: Alex Dibrivnyi Date: Thu, 9 Feb 2017 20:41:49 +0200 Subject: [PATCH] Added correct error handling when facebook/twitter is not installed. (Close #8) --- .../aboutbox/activity/AboutActivity.java | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/library/src/main/java/com/eggheadgames/aboutbox/activity/AboutActivity.java b/library/src/main/java/com/eggheadgames/aboutbox/activity/AboutActivity.java index d9d1cf0..f3e024c 100644 --- a/library/src/main/java/com/eggheadgames/aboutbox/activity/AboutActivity.java +++ b/library/src/main/java/com/eggheadgames/aboutbox/activity/AboutActivity.java @@ -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