From c7d4edaedeb13b8dd25935e09fc7d14010020155 Mon Sep 17 00:00:00 2001 From: Mehmet Date: Wed, 6 Nov 2019 17:46:55 +0000 Subject: [PATCH] Catch ActivityNotFound exception to prevent crashes --- .../bridge/BaseSelectOpponentsUiRequest.java | 2 +- .../games/bridge/CaptureOverlayUiRequest.java | 2 +- .../google/games/bridge/InboxUiRequest.java | 2 +- .../games/bridge/SelectSnapshotUiRequest.java | 2 +- .../bridge/ShowInvitationInboxUIRequest.java | 2 +- .../bridge/ShowWaitingRoomUiRequest.java | 2 +- .../google/games/bridge/SimpleUiRequest.java | 2 +- .../java/com/google/games/bridge/Utils.java | 24 +++++++++++++++++++ 8 files changed, 31 insertions(+), 7 deletions(-) create mode 100644 source/SupportLib/PlayGamesPluginSupport/src/main/java/com/google/games/bridge/Utils.java diff --git a/source/SupportLib/PlayGamesPluginSupport/src/main/java/com/google/games/bridge/BaseSelectOpponentsUiRequest.java b/source/SupportLib/PlayGamesPluginSupport/src/main/java/com/google/games/bridge/BaseSelectOpponentsUiRequest.java index b133748f0..bad912d03 100644 --- a/source/SupportLib/PlayGamesPluginSupport/src/main/java/com/google/games/bridge/BaseSelectOpponentsUiRequest.java +++ b/source/SupportLib/PlayGamesPluginSupport/src/main/java/com/google/games/bridge/BaseSelectOpponentsUiRequest.java @@ -59,7 +59,7 @@ public void process(final HelperFragment helperFragment) { new OnSuccessListener() { @Override public void onSuccess(Intent intent) { - helperFragment.startActivityForResult(intent, HelperFragment.RC_SELECT_OPPONENTS_UI); + Utils.startActivityForResult(helperFragment, intent, HelperFragment.RC_SELECT_OPPONENTS_UI); } }) .addOnFailureListener( diff --git a/source/SupportLib/PlayGamesPluginSupport/src/main/java/com/google/games/bridge/CaptureOverlayUiRequest.java b/source/SupportLib/PlayGamesPluginSupport/src/main/java/com/google/games/bridge/CaptureOverlayUiRequest.java index fc8b6279a..7b97cce19 100644 --- a/source/SupportLib/PlayGamesPluginSupport/src/main/java/com/google/games/bridge/CaptureOverlayUiRequest.java +++ b/source/SupportLib/PlayGamesPluginSupport/src/main/java/com/google/games/bridge/CaptureOverlayUiRequest.java @@ -25,7 +25,7 @@ public void process(final HelperFragment helperFragment) { new OnSuccessListener() { @Override public void onSuccess(Intent intent) { - helperFragment.startActivityForResult(intent, HelperFragment.RC_CAPTURE_OVERLAY_UI); + Utils.startActivityForResult(helperFragment, intent, HelperFragment.RC_CAPTURE_OVERLAY_UI); helperFragment.finishRequest(CaptureOverlayUiRequest.this); } }) diff --git a/source/SupportLib/PlayGamesPluginSupport/src/main/java/com/google/games/bridge/InboxUiRequest.java b/source/SupportLib/PlayGamesPluginSupport/src/main/java/com/google/games/bridge/InboxUiRequest.java index 5ff98ee57..5559f7c6c 100644 --- a/source/SupportLib/PlayGamesPluginSupport/src/main/java/com/google/games/bridge/InboxUiRequest.java +++ b/source/SupportLib/PlayGamesPluginSupport/src/main/java/com/google/games/bridge/InboxUiRequest.java @@ -45,7 +45,7 @@ public void process(final HelperFragment helperFragment) { new OnSuccessListener() { @Override public void onSuccess(Intent intent) { - helperFragment.startActivityForResult(intent, HelperFragment.RC_INBOX_UI); + Utils.startActivityForResult(helperFragment, intent, HelperFragment.RC_INBOX_UI); } }) .addOnFailureListener( diff --git a/source/SupportLib/PlayGamesPluginSupport/src/main/java/com/google/games/bridge/SelectSnapshotUiRequest.java b/source/SupportLib/PlayGamesPluginSupport/src/main/java/com/google/games/bridge/SelectSnapshotUiRequest.java index e861690a5..6b6a86dab 100644 --- a/source/SupportLib/PlayGamesPluginSupport/src/main/java/com/google/games/bridge/SelectSnapshotUiRequest.java +++ b/source/SupportLib/PlayGamesPluginSupport/src/main/java/com/google/games/bridge/SelectSnapshotUiRequest.java @@ -70,7 +70,7 @@ public void process(final HelperFragment helperFragment) { new OnSuccessListener() { @Override public void onSuccess(Intent intent) { - helperFragment.startActivityForResult(intent, HelperFragment.RC_SELECT_SNAPSHOT_UI); + Utils.startActivityForResult(helperFragment, intent, HelperFragment.RC_SELECT_SNAPSHOT_UI); } }) .addOnFailureListener( diff --git a/source/SupportLib/PlayGamesPluginSupport/src/main/java/com/google/games/bridge/ShowInvitationInboxUIRequest.java b/source/SupportLib/PlayGamesPluginSupport/src/main/java/com/google/games/bridge/ShowInvitationInboxUIRequest.java index 5b5e5abc7..9b01f4849 100644 --- a/source/SupportLib/PlayGamesPluginSupport/src/main/java/com/google/games/bridge/ShowInvitationInboxUIRequest.java +++ b/source/SupportLib/PlayGamesPluginSupport/src/main/java/com/google/games/bridge/ShowInvitationInboxUIRequest.java @@ -51,7 +51,7 @@ public void process(final HelperFragment helperFragment) { new OnSuccessListener() { @Override public void onSuccess(Intent intent) { - helperFragment.startActivityForResult(intent, HelperFragment.RC_SHOW_INVITATION_INBOX_UI); + Utils.startActivityForResult(helperFragment, intent, HelperFragment.RC_SHOW_INVITATION_INBOX_UI); } }) .addOnFailureListener( diff --git a/source/SupportLib/PlayGamesPluginSupport/src/main/java/com/google/games/bridge/ShowWaitingRoomUiRequest.java b/source/SupportLib/PlayGamesPluginSupport/src/main/java/com/google/games/bridge/ShowWaitingRoomUiRequest.java index 1011e2fd7..7ff11edf0 100644 --- a/source/SupportLib/PlayGamesPluginSupport/src/main/java/com/google/games/bridge/ShowWaitingRoomUiRequest.java +++ b/source/SupportLib/PlayGamesPluginSupport/src/main/java/com/google/games/bridge/ShowWaitingRoomUiRequest.java @@ -64,7 +64,7 @@ public void process(final HelperFragment helperFragment) { new OnSuccessListener() { @Override public void onSuccess(Intent intent) { - helperFragment.startActivityForResult(intent, HelperFragment.RC_SHOW_WAITING_ROOM_UI); + Utils.startActivityForResult(helperFragment, intent, HelperFragment.RC_SHOW_WAITING_ROOM_UI); } }) .addOnFailureListener( diff --git a/source/SupportLib/PlayGamesPluginSupport/src/main/java/com/google/games/bridge/SimpleUiRequest.java b/source/SupportLib/PlayGamesPluginSupport/src/main/java/com/google/games/bridge/SimpleUiRequest.java index 2e7e29410..8ccf1b534 100644 --- a/source/SupportLib/PlayGamesPluginSupport/src/main/java/com/google/games/bridge/SimpleUiRequest.java +++ b/source/SupportLib/PlayGamesPluginSupport/src/main/java/com/google/games/bridge/SimpleUiRequest.java @@ -33,7 +33,7 @@ public void process(final HelperFragment helperFragment) { new OnSuccessListener() { @Override public void onSuccess(Intent intent) { - helperFragment.startActivityForResult(intent, HelperFragment.RC_SIMPLE_UI); + Utils.startActivityForResult(helperFragment, intent, HelperFragment.RC_SIMPLE_UI); } }) .addOnFailureListener( diff --git a/source/SupportLib/PlayGamesPluginSupport/src/main/java/com/google/games/bridge/Utils.java b/source/SupportLib/PlayGamesPluginSupport/src/main/java/com/google/games/bridge/Utils.java new file mode 100644 index 000000000..1b3ff35e8 --- /dev/null +++ b/source/SupportLib/PlayGamesPluginSupport/src/main/java/com/google/games/bridge/Utils.java @@ -0,0 +1,24 @@ +package com.google.games.bridge; + +import android.app.Fragment; +import android.content.ActivityNotFoundException; +import android.content.Intent; +import android.util.Log; + +/** + * Utility functions + */ +public final class Utils { + + private static final String TAG = "Utils"; + + private Utils() {} + + public static void startActivityForResult(Fragment fragment, Intent intent, int requestCode) { + try { + fragment.startActivityForResult(intent, requestCode); + } catch (ActivityNotFoundException e) { + Log.e(TAG,"Activity not found. Please install Play Games App."); + } + } +}