Handle some error events in AndroidPlatform

This commit is contained in:
Ellpeck 2020-07-26 14:41:58 +02:00
parent efbf197e72
commit 1f0c10a5e3

View file

@ -66,6 +66,7 @@ namespace Android {
AndroidEnvironment.UnhandledExceptionRaiser += (o, args) => GameAnalytics.NewErrorEvent(GAErrorSeverity.Critical, args.Exception.ToString()); AndroidEnvironment.UnhandledExceptionRaiser += (o, args) => GameAnalytics.NewErrorEvent(GAErrorSeverity.Critical, args.Exception.ToString());
// Ads // Ads
try {
var ad = new AdView(this.activity) { var ad = new AdView(this.activity) {
AdUnitId = "ca-app-pub-5754829579653773/7841535920", AdUnitId = "ca-app-pub-5754829579653773/7841535920",
AdSize = AdSize.SmartBanner AdSize = AdSize.SmartBanner
@ -74,8 +75,12 @@ namespace Android {
.AddTestDevice("14B965C6457E17D2808061ADF7E34923") .AddTestDevice("14B965C6457E17D2808061ADF7E34923")
.Build()); .Build());
this.adLayout.AddView(ad); this.adLayout.AddView(ad);
} catch (Exception e) {
GameAnalytics.NewErrorEvent(GAErrorSeverity.Error, "Ads " + e);
}
// Google Play game services // Google Play game services
try {
this.GoogleApi = new GoogleApiClient.Builder(this.activity) this.GoogleApi = new GoogleApiClient.Builder(this.activity)
.AddApi(GamesClass.API) .AddApi(GamesClass.API)
.AddScope(GamesClass.ScopeGames) .AddScope(GamesClass.ScopeGames)
@ -88,6 +93,9 @@ namespace Android {
}) })
.Build(); .Build();
this.GoogleApi.Connect(); this.GoogleApi.Connect();
} catch (Exception e) {
GameAnalytics.NewErrorEvent(GAErrorSeverity.Error, "GoogleApiClient " + e);
}
#if DEBUG #if DEBUG
// Sanity check to ensure that all achievements are mapped // Sanity check to ensure that all achievements are mapped
@ -114,18 +122,26 @@ namespace Android {
} }
public override bool GainAchievement(Achievement achievement) { public override bool GainAchievement(Achievement achievement) {
try {
if (this.GoogleApi != null && this.GoogleApi.IsConnected) { if (this.GoogleApi != null && this.GoogleApi.IsConnected) {
GamesClass.Achievements.Unlock(this.GoogleApi, AchievementIds[achievement.Name]); GamesClass.Achievements.Unlock(this.GoogleApi, AchievementIds[achievement.Name]);
return true; return true;
} }
} catch (Exception e) {
GameAnalytics.NewErrorEvent(GAErrorSeverity.Error, "GainAchievement " + e);
}
return false; return false;
} }
public override void ShowAchievements() { public override void ShowAchievements() {
try {
if (this.GoogleApi == null || !this.GoogleApi.IsConnected) if (this.GoogleApi == null || !this.GoogleApi.IsConnected)
return; return;
var intent = GamesClass.Achievements.GetAchievementsIntent(this.GoogleApi); var intent = GamesClass.Achievements.GetAchievementsIntent(this.GoogleApi);
this.activity.StartActivityForResult(intent, ShowAchievementsRequest); this.activity.StartActivityForResult(intent, ShowAchievementsRequest);
} catch (Exception e) {
GameAnalytics.NewErrorEvent(GAErrorSeverity.Error, "ShowAchievements " + e);
}
} }
} }