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,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);
}
}
}