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());
// Ads
try {
var ad = new AdView(this.activity) {
AdUnitId = "ca-app-pub-5754829579653773/7841535920",
AdSize = AdSize.SmartBanner
@ -74,8 +75,12 @@ namespace Android {
.AddTestDevice("14B965C6457E17D2808061ADF7E34923")
.Build());
this.adLayout.AddView(ad);
} catch (Exception e) {
GameAnalytics.NewErrorEvent(GAErrorSeverity.Error, "Ads " + e);
}
// Google Play game services
try {
this.GoogleApi = new GoogleApiClient.Builder(this.activity)
.AddApi(GamesClass.API)
.AddScope(GamesClass.ScopeGames)
@ -88,6 +93,9 @@ namespace Android {
})
.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) {
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() {
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);
}
}
}