Handle some error events in AndroidPlatform
This commit is contained in:
parent
efbf197e72
commit
1f0c10a5e3
1 changed files with 43 additions and 27 deletions
|
@ -66,28 +66,36 @@ 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
|
||||||
var ad = new AdView(this.activity) {
|
try {
|
||||||
AdUnitId = "ca-app-pub-5754829579653773/7841535920",
|
var ad = new AdView(this.activity) {
|
||||||
AdSize = AdSize.SmartBanner
|
AdUnitId = "ca-app-pub-5754829579653773/7841535920",
|
||||||
};
|
AdSize = AdSize.SmartBanner
|
||||||
ad.LoadAd(new AdRequest.Builder()
|
};
|
||||||
.AddTestDevice("14B965C6457E17D2808061ADF7E34923")
|
ad.LoadAd(new AdRequest.Builder()
|
||||||
.Build());
|
.AddTestDevice("14B965C6457E17D2808061ADF7E34923")
|
||||||
this.adLayout.AddView(ad);
|
.Build());
|
||||||
|
this.adLayout.AddView(ad);
|
||||||
|
} catch (Exception e) {
|
||||||
|
GameAnalytics.NewErrorEvent(GAErrorSeverity.Error, "Ads " + e);
|
||||||
|
}
|
||||||
|
|
||||||
// Google Play game services
|
// Google Play game services
|
||||||
this.GoogleApi = new GoogleApiClient.Builder(this.activity)
|
try {
|
||||||
.AddApi(GamesClass.API)
|
this.GoogleApi = new GoogleApiClient.Builder(this.activity)
|
||||||
.AddScope(GamesClass.ScopeGames)
|
.AddApi(GamesClass.API)
|
||||||
.AddOnConnectionFailedListener(res => {
|
.AddScope(GamesClass.ScopeGames)
|
||||||
if (res.HasResolution) {
|
.AddOnConnectionFailedListener(res => {
|
||||||
res.StartResolutionForResult(this.activity, GooglePlayLoginRequest);
|
if (res.HasResolution) {
|
||||||
} else {
|
res.StartResolutionForResult(this.activity, GooglePlayLoginRequest);
|
||||||
throw new GoogleApiClientConnectionException(res);
|
} else {
|
||||||
}
|
throw new GoogleApiClientConnectionException(res);
|
||||||
})
|
}
|
||||||
.Build();
|
})
|
||||||
this.GoogleApi.Connect();
|
.Build();
|
||||||
|
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) {
|
||||||
if (this.GoogleApi != null && this.GoogleApi.IsConnected) {
|
try {
|
||||||
GamesClass.Achievements.Unlock(this.GoogleApi, AchievementIds[achievement.Name]);
|
if (this.GoogleApi != null && this.GoogleApi.IsConnected) {
|
||||||
return true;
|
GamesClass.Achievements.Unlock(this.GoogleApi, AchievementIds[achievement.Name]);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
GameAnalytics.NewErrorEvent(GAErrorSeverity.Error, "GainAchievement " + e);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void ShowAchievements() {
|
public override void ShowAchievements() {
|
||||||
if (this.GoogleApi == null || !this.GoogleApi.IsConnected)
|
try {
|
||||||
return;
|
if (this.GoogleApi == null || !this.GoogleApi.IsConnected)
|
||||||
var intent = GamesClass.Achievements.GetAchievementsIntent(this.GoogleApi);
|
return;
|
||||||
this.activity.StartActivityForResult(intent, ShowAchievementsRequest);
|
var intent = GamesClass.Achievements.GetAchievementsIntent(this.GoogleApi);
|
||||||
|
this.activity.StartActivityForResult(intent, ShowAchievementsRequest);
|
||||||
|
} catch (Exception e) {
|
||||||
|
GameAnalytics.NewErrorEvent(GAErrorSeverity.Error, "ShowAchievements " + e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue