From 1f0c10a5e3f245d18f5034e689f2b248ca65fdf9 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Sun, 26 Jul 2020 14:41:58 +0200 Subject: [PATCH] Handle some error events in AndroidPlatform --- Android/AndroidPlatform.cs | 70 +++++++++++++++++++++++--------------- 1 file changed, 43 insertions(+), 27 deletions(-) diff --git a/Android/AndroidPlatform.cs b/Android/AndroidPlatform.cs index 7c27609..c0d41f5 100644 --- a/Android/AndroidPlatform.cs +++ b/Android/AndroidPlatform.cs @@ -66,28 +66,36 @@ namespace Android { AndroidEnvironment.UnhandledExceptionRaiser += (o, args) => GameAnalytics.NewErrorEvent(GAErrorSeverity.Critical, args.Exception.ToString()); // Ads - var ad = new AdView(this.activity) { - AdUnitId = "ca-app-pub-5754829579653773/7841535920", - AdSize = AdSize.SmartBanner - }; - ad.LoadAd(new AdRequest.Builder() - .AddTestDevice("14B965C6457E17D2808061ADF7E34923") - .Build()); - this.adLayout.AddView(ad); + try { + var ad = new AdView(this.activity) { + AdUnitId = "ca-app-pub-5754829579653773/7841535920", + AdSize = AdSize.SmartBanner + }; + ad.LoadAd(new AdRequest.Builder() + .AddTestDevice("14B965C6457E17D2808061ADF7E34923") + .Build()); + this.adLayout.AddView(ad); + } catch (Exception e) { + GameAnalytics.NewErrorEvent(GAErrorSeverity.Error, "Ads " + e); + } // Google Play game services - this.GoogleApi = new GoogleApiClient.Builder(this.activity) - .AddApi(GamesClass.API) - .AddScope(GamesClass.ScopeGames) - .AddOnConnectionFailedListener(res => { - if (res.HasResolution) { - res.StartResolutionForResult(this.activity, GooglePlayLoginRequest); - } else { - throw new GoogleApiClientConnectionException(res); - } - }) - .Build(); - this.GoogleApi.Connect(); + try { + this.GoogleApi = new GoogleApiClient.Builder(this.activity) + .AddApi(GamesClass.API) + .AddScope(GamesClass.ScopeGames) + .AddOnConnectionFailedListener(res => { + if (res.HasResolution) { + res.StartResolutionForResult(this.activity, GooglePlayLoginRequest); + } else { + throw new GoogleApiClientConnectionException(res); + } + }) + .Build(); + this.GoogleApi.Connect(); + } catch (Exception e) { + GameAnalytics.NewErrorEvent(GAErrorSeverity.Error, "GoogleApiClient " + e); + } #if DEBUG // Sanity check to ensure that all achievements are mapped @@ -114,18 +122,26 @@ namespace Android { } public override bool GainAchievement(Achievement achievement) { - if (this.GoogleApi != null && this.GoogleApi.IsConnected) { - GamesClass.Achievements.Unlock(this.GoogleApi, AchievementIds[achievement.Name]); - return true; + try { + if (this.GoogleApi != null && this.GoogleApi.IsConnected) { + GamesClass.Achievements.Unlock(this.GoogleApi, AchievementIds[achievement.Name]); + return true; + } + } catch (Exception e) { + GameAnalytics.NewErrorEvent(GAErrorSeverity.Error, "GainAchievement " + e); } return false; } public override void ShowAchievements() { - if (this.GoogleApi == null || !this.GoogleApi.IsConnected) - return; - var intent = GamesClass.Achievements.GetAchievementsIntent(this.GoogleApi); - this.activity.StartActivityForResult(intent, ShowAchievementsRequest); + try { + if (this.GoogleApi == null || !this.GoogleApi.IsConnected) + return; + var intent = GamesClass.Achievements.GetAchievementsIntent(this.GoogleApi); + this.activity.StartActivityForResult(intent, ShowAchievementsRequest); + } catch (Exception e) { + GameAnalytics.NewErrorEvent(GAErrorSeverity.Error, "ShowAchievements " + e); + } } }