public void GetPlayerStats(IntPtr apiClient, Action <CommonStatusCodes, PlayGamesLocalUser.PlayerStats> callback) { GoogleApiClient client = new GoogleApiClient(apiClient); StatsResultCallback resCallback; try { resCallback = new StatsResultCallback((result, stats) => { Debug.Log("Result for getStats: " + result); PlayGamesLocalUser.PlayerStats s = null; if (stats != null) { s = new PlayGamesLocalUser.PlayerStats(); s.AvgSessonLength = stats.getAverageSessionLength(); s.DaysSinceLastPlayed = stats.getDaysSinceLastPlayed(); s.NumberOfPurchases = stats.getNumberOfPurchases(); s.NumOfSessions = stats.getNumberOfSessions(); s.SessPercentile = stats.getSessionPercentile(); s.SpendPercentile = stats.getSpendPercentile(); } callback((CommonStatusCodes)result, s); }); } catch (Exception e) { Debug.LogException(e); callback(CommonStatusCodes.DeveloperError, null); return; } PendingResult <Stats_LoadPlayerStatsResultObject> pr = Games.Stats.loadPlayerStats(client, true); pr.setResultCallback(resCallback); }
public static async Task AsAsync(this PendingResult pr) { var rc = new AwaitableResultCallback <Statuses> (); pr.SetResultCallback(rc); await rc.AwaitAsync(); }
public static TaskAwaiter <TResult> GetAwaiter <TResult> (this PendingResult pr) where TResult : class, IResult { var rc = new AwaitableResultCallback <TResult> (); pr.SetResultCallback(rc); return(rc.GetAwaiter()); }
public static TaskAwaiter <IResult> GetAwaiter(this PendingResult pr) { var rc = new AwaitableResultCallback <IResult> (); pr.SetResultCallback(rc); return(rc.GetAwaiter()); }
public static Task <TResult> AsAsync <TResult> (this PendingResult pr) where TResult : class, IResult { var rc = new AwaitableResultCallback <TResult> (); pr.SetResultCallback(rc); return(rc.AwaitAsync()); }
internal void DoFetchToken(Action callback) { //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Expected O, but got Unknown object[] array = new object[9]; jvalue[] array2 = AndroidJNIHelper.CreateJNIArgArray(array); try { AndroidJavaClass val = new AndroidJavaClass("com.google.games.bridge.TokenFragment"); try { AndroidJavaObject activity = GetActivity(); try { IntPtr staticMethodID = AndroidJNI.GetStaticMethodID(val.GetRawClass(), "fetchToken", "(Landroid/app/Activity;ZZZLjava/lang/String;Z[Ljava/lang/String;ZLjava/lang/String;)Lcom/google/android/gms/common/api/PendingResult;"); array2[0].l = activity.GetRawObject(); array2[1].z = requestAuthCode; array2[2].z = requestEmail; array2[3].z = requestIdToken; array2[4].l = AndroidJNI.NewStringUTF(webClientId); array2[5].z = forceRefresh; array2[6].l = AndroidJNIHelper.ConvertToJNIArray((Array)oauthScopes.ToArray()); array2[7].z = hidePopups; array2[8].l = AndroidJNI.NewStringUTF(accountName); IntPtr ptr = AndroidJNI.CallStaticObjectMethod(val.GetRawClass(), staticMethodID, array2); PendingResult <TokenResult> pendingResult = new PendingResult <TokenResult>(ptr); pendingResult.setResultCallback(new TokenResultCallback(delegate(int rc, string authCode, string email, string idToken) { this.authCode = authCode; this.email = email; this.idToken = idToken; callback(); })); } finally { ((IDisposable)activity)?.Dispose(); } } finally { ((IDisposable)val)?.Dispose(); } } catch (Exception ex) { Logger.e("Exception launching token request: " + ex.Message); Logger.e(ex.ToString()); } finally { AndroidJNIHelper.DeleteJNIArgArray(array, array2); } }
internal void DoFetchToken(bool silent, Action <int> callback) { object[] objectArray = new object[10]; jvalue[] jArgs = AndroidJNIHelper.CreateJNIArgArray(objectArray); try { using (var bridgeClass = new AndroidJavaClass(TokenFragmentClass)) { using (var currentActivity = GetActivity()) { // Unity no longer supports constructing an AndroidJavaObject using an IntPtr, // so I have to manually munge with JNI here. IntPtr methodId = AndroidJNI.GetStaticMethodID(bridgeClass.GetRawClass(), FetchTokenMethod, FetchTokenSignature); jArgs[0].l = currentActivity.GetRawObject(); jArgs[1].z = silent; jArgs[2].z = requestAuthCode; jArgs[3].z = requestEmail; jArgs[4].z = requestIdToken; jArgs[5].l = AndroidJNI.NewStringUTF(webClientId); jArgs[6].z = forceRefresh; jArgs[7].l = AndroidJNIHelper.ConvertToJNIArray(oauthScopes.ToArray()); jArgs[8].z = hidePopups; jArgs[9].l = AndroidJNI.NewStringUTF(accountName); IntPtr ptr = AndroidJNI.CallStaticObjectMethod(bridgeClass.GetRawClass(), methodId, jArgs); PendingResult <TokenResult> pr = new PendingResult <TokenResult>(ptr); pr.setResultCallback(new TokenResultCallback((rc, authCode, email, idToken) => { this.authCode = authCode; this.email = email; this.idToken = idToken; callback(rc); })); } } } catch (Exception e) { OurUtils.Logger.e("Exception launching token request: " + e.Message); OurUtils.Logger.e(e.ToString()); } finally { AndroidJNIHelper.DeleteJNIArgArray(objectArray, jArgs); } }
public override void OnReceive(Context context, Intent intent) { PendingResult result = GoAsync(); // If app restriction settings are already created, they will be included in the Bundle // as key/value pairs. Bundle existingRestrictions = intent.GetBundleExtra(Intent.ExtraRestrictionsBundle); Log.Info(TAG, "existingRestrictions = " + existingRestrictions); Thread thread = new Thread(new ThreadStart(delegate { CreateRestrictions(context, result, existingRestrictions); })); thread.Start(); }
public void IsLocationEnabled(Action <bool> returnAction) { InitializeGoogleAPI(); if (mGoogleApiClient == null || CheckPermissions() == false) { returnAction(false); return; } mFusedLocationProviderClient = LocationServices.GetFusedLocationProviderClient(Android.App.Application.Context); mGeofencingClient = LocationServices.GetGeofencingClient(Application.Context); mGeofenceList = new List <Android.Gms.Location.IGeofence>(); int locationRequestPriority = LocationRequest.PriorityBalancedPowerAccuracy; switch (CrossGeofence.GeofencePriority) { case GeofencePriority.HighAccuracy: locationRequestPriority = LocationRequest.PriorityHighAccuracy; break; case GeofencePriority.LowAccuracy: locationRequestPriority = LocationRequest.PriorityLowPower; break; case GeofencePriority.LowestAccuracy: locationRequestPriority = LocationRequest.PriorityNoPower; break; } mLocationRequest = new LocationRequest(); mLocationRequest.SetPriority(locationRequestPriority); mLocationRequest.SetInterval(CrossGeofence.LocationUpdatesInterval); mLocationRequest.SetFastestInterval(CrossGeofence.FastestLocationUpdatesInterval); LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder().AddLocationRequest(mLocationRequest); PendingResult pendingResult = LocationServices.SettingsApi.CheckLocationSettings(mGoogleApiClient, builder.Build()); pendingResult.SetResultCallback((LocationSettingsResult locationSettingsResult) => { if (locationSettingsResult != null) { returnAction(locationSettingsResult.Status.StatusCode <= CommonStatusCodes.Success); } }); System.Diagnostics.Debug.WriteLine("End of IsLocationEnabled, clients should be created"); }
internal static void FetchToken(bool fetchAuthCode, bool fetchEmail, bool fetchIdToken, string webClientId, bool forceRefresh, Action <int, string, string, string> callback) { //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Expected O, but got Unknown object[] array = new object[7]; jvalue[] array2 = AndroidJNIHelper.CreateJNIArgArray(array); try { AndroidJavaClass val = new AndroidJavaClass("com.google.games.bridge.TokenFragment"); try { AndroidJavaObject activity = GetActivity(); try { IntPtr staticMethodID = AndroidJNI.GetStaticMethodID(val.GetRawClass(), "fetchToken", "(Landroid/app/Activity;ZZZLjava/lang/String;Z[Ljava/lang/String;ZLjava/lang/String;)Lcom/google/android/gms/common/api/PendingResult;"); array2[0].l = activity.GetRawObject(); array2[1].z = fetchAuthCode; array2[2].z = fetchEmail; array2[3].z = fetchIdToken; array2[4].l = AndroidJNI.NewStringUTF(webClientId); array2[5].z = forceRefresh; IntPtr ptr = AndroidJNI.CallStaticObjectMethod(val.GetRawClass(), staticMethodID, array2); PendingResult <TokenResult> pendingResult = new PendingResult <TokenResult>(ptr); pendingResult.setResultCallback(new TokenResultCallback(callback)); } finally { ((IDisposable)activity)?.Dispose(); } } finally { ((IDisposable)val)?.Dispose(); } } catch (Exception ex) { Logger.e("Exception launching token request: " + ex.Message); Logger.e(ex.ToString()); } finally { AndroidJNIHelper.DeleteJNIArgArray(array, array2); } }
public void GetPlayerStats(IntPtr apiClient, Action <CommonStatusCodes, GooglePlayGames.BasicApi.PlayerStats> callback) { GoogleApiClient client = new GoogleApiClient(apiClient); StatsResultCallback resCallback; try { resCallback = new StatsResultCallback((result, stats) => { #if BUILD_TYPE_DEBUG Debug.Log("Result for getStats: " + result); #endif GooglePlayGames.BasicApi.PlayerStats s = null; if (stats != null) { s = new GooglePlayGames.BasicApi.PlayerStats(); s.AvgSessonLength = stats.getAverageSessionLength(); s.DaysSinceLastPlayed = stats.getDaysSinceLastPlayed(); s.NumberOfPurchases = stats.getNumberOfPurchases(); s.NumberOfSessions = stats.getNumberOfSessions(); s.SessPercentile = stats.getSessionPercentile(); s.SpendPercentile = stats.getSpendPercentile(); s.ChurnProbability = stats.getChurnProbability(); s.SpendProbability = stats.getSpendProbability(); s.HighSpenderProbability = stats.getHighSpenderProbability(); s.TotalSpendNext28Days = stats.getTotalSpendNext28Days(); } callback((CommonStatusCodes)result, s); }); } catch (Exception e) { Debug.LogException(e); callback(CommonStatusCodes.DeveloperError, null); return; } PendingResult <Stats_LoadPlayerStatsResultObject> pr = Games.Stats.loadPlayerStats(client, true); pr.setResultCallback(resCallback); }
internal static void FetchToken(string scope, string rationale, bool fetchEmail, bool fetchAccessToken, bool fetchIdToken, Action <int, string, string, string> callback) { object[] objectArray = new object[6]; jvalue[] jArgs = AndroidJNIHelper.CreateJNIArgArray(objectArray); try { using (var bridgeClass = new AndroidJavaClass(TokenFragmentClass)) { using (var currentActivity = AndroidTokenClient.GetActivity()) { // Unity no longer supports constructing an AndroidJavaObject using an IntPtr, // so I have to manually munge with JNI here. IntPtr methodId = AndroidJNI.GetStaticMethodID(bridgeClass.GetRawClass(), FetchTokenMethod, FetchTokenSignature); jArgs[0].l = currentActivity.GetRawObject(); jArgs[1].l = AndroidJNI.NewStringUTF(rationale); jArgs[2].z = fetchEmail; jArgs[3].z = fetchAccessToken; jArgs[4].z = fetchIdToken; jArgs[5].l = AndroidJNI.NewStringUTF(scope); GooglePlayGames.OurUtils.Logger.d("---->> Calling Fetch: " + methodId + " scope: " + scope); IntPtr ptr = AndroidJNI.CallStaticObjectMethod(bridgeClass.GetRawClass(), methodId, jArgs); GooglePlayGames.OurUtils.Logger.d("<<<------- Got return of " + ptr); PendingResult <TokenResult> pr = new PendingResult <TokenResult>(ptr); pr.setResultCallback(new TokenResultCallback(callback)); } } } catch (Exception e) { GooglePlayGames.OurUtils.Logger.e("Exception launching token request: " + e.Message); GooglePlayGames.OurUtils.Logger.e(e.ToString()); } finally { AndroidJNIHelper.DeleteJNIArgArray(objectArray, jArgs); } }
/// <summary> /// Gets another server auth code. /// </summary> /// <remarks>This method should be called after authenticating, and exchanging /// the initial server auth code for a token. This is implemented by signing in /// silently, which if successful returns almost immediately and with a new /// server auth code. /// </remarks> /// <param name="reAuthenticateIfNeeded">Calls Authenticate if needed when /// retrieving another auth code. </param> /// <param name="callback">Callback.</param> public void GetAnotherServerAuthCode(bool reAuthenticateIfNeeded, Action <string> callback) { object[] objectArray = new object[3]; jvalue[] jArgs = AndroidJNIHelper.CreateJNIArgArray(objectArray); try { using (var bridgeClass = new AndroidJavaClass(TokenFragmentClass)) { using (var currentActivity = GetActivity()) { // Unity no longer supports constructing an AndroidJavaObject using an IntPtr, // so I have to manually munge with JNI here. IntPtr methodId = AndroidJNI.GetStaticMethodID(bridgeClass.GetRawClass(), GetAnotherAuthCodeMethod, GetAnotherAuthCodeSignature); jArgs[0].l = currentActivity.GetRawObject(); jArgs[1].z = reAuthenticateIfNeeded; jArgs[2].l = AndroidJNI.NewStringUTF(webClientId); IntPtr ptr = AndroidJNI.CallStaticObjectMethod(bridgeClass.GetRawClass(), methodId, jArgs); PendingResult <TokenResult> pr = new PendingResult <TokenResult>(ptr); pr.setResultCallback(new TokenResultCallback((rc, authCode, email, idToken) => { this.authCode = authCode; callback(authCode); })); } } } catch (Exception e) { OurUtils.Logger.e("Exception launching auth code request: " + e.Message); OurUtils.Logger.e(e.ToString()); } finally { AndroidJNIHelper.DeleteJNIArgArray(objectArray, jArgs); } }
internal static void FetchToken(bool fetchAuthCode, bool fetchEmail, bool fetchIdToken, string webClientId, bool forceRefresh, Action <int, string, string, string> callback) { object[] objectArray = new object[7]; jvalue[] jArgs = AndroidJNIHelper.CreateJNIArgArray(objectArray); try { using (var bridgeClass = new AndroidJavaClass(TokenFragmentClass)) { using (var currentActivity = AndroidTokenClient.GetActivity()) { // Unity no longer supports constructing an AndroidJavaObject using an IntPtr, // so I have to manually munge with JNI here. IntPtr methodId = AndroidJNI.GetStaticMethodID(bridgeClass.GetRawClass(), FetchTokenMethod, FetchTokenSignature); jArgs[0].l = currentActivity.GetRawObject(); jArgs[1].z = fetchAuthCode; jArgs[2].z = fetchEmail; jArgs[3].z = fetchIdToken; jArgs[4].l = AndroidJNI.NewStringUTF(webClientId); jArgs[5].z = forceRefresh; IntPtr ptr = AndroidJNI.CallStaticObjectMethod(bridgeClass.GetRawClass(), methodId, jArgs); PendingResult <TokenResult> pr = new PendingResult <TokenResult>(ptr); pr.setResultCallback(new TokenResultCallback(callback)); } } } catch (Exception e) { OurUtils.Logger.e("Exception launching token request: " + e.Message); OurUtils.Logger.e(e.ToString()); } finally { AndroidJNIHelper.DeleteJNIArgArray(objectArray, jArgs); } }
public void GetPlayerStats(IntPtr apiClient, Action <CommonStatusCodes, GooglePlayGames.BasicApi.PlayerStats> callback) { GoogleApiClient arg_GoogleApiClient_ = new GoogleApiClient(apiClient); StatsResultCallback resultCallback; try { resultCallback = new StatsResultCallback(delegate(int result, Com.Google.Android.Gms.Games.Stats.PlayerStats stats) { Debug.Log((object)("Result for getStats: " + result)); GooglePlayGames.BasicApi.PlayerStats arg = null; if (stats != null) { arg = new GooglePlayGames.BasicApi.PlayerStats { AvgSessonLength = stats.getAverageSessionLength(), DaysSinceLastPlayed = stats.getDaysSinceLastPlayed(), NumberOfPurchases = stats.getNumberOfPurchases(), NumberOfSessions = stats.getNumberOfSessions(), SessPercentile = stats.getSessionPercentile(), SpendPercentile = stats.getSpendPercentile(), ChurnProbability = stats.getChurnProbability(), SpendProbability = stats.getSpendProbability(), HighSpenderProbability = stats.getHighSpenderProbability(), TotalSpendNext28Days = stats.getTotalSpendNext28Days() }; } callback((CommonStatusCodes)result, arg); }); } catch (Exception ex) { Debug.LogException(ex); callback(CommonStatusCodes.DeveloperError, null); return; IL_0049 :; } PendingResult <Stats_LoadPlayerStatsResultObject> pendingResult = Games.Stats.loadPlayerStats(arg_GoogleApiClient_, true); pendingResult.setResultCallback(resultCallback); }
public static void SetResultCallback <TResult> (this PendingResult pr, Action <TResult> callback) where TResult : class, IResult { pr.SetResultCallback(new ResultCallback <TResult> (callback)); }
private void CreateRestrictions (Context context, PendingResult result, Bundle existingRestrictions) { // The incoming restrictions bundle contains key/value pairs representing existing app // restrictions for this package. In order to retain existing app restrictions, you need to // construct new restriction entries and then copy in any existing values for the new keys. List <IParcelable> newEntries = InitRestrictions (context); // If app restrictions were not previously configured for the package, create the default // restrictions entries and return them. if (existingRestrictions == null) { var extras = new Bundle (); extras.PutParcelableArrayList (Intent.ExtraRestrictionsList, newEntries); result.SetResult (Result.Ok, null, extras); result.Finish (); return; } // Retains current restriction settings by transferring existing restriction entries to // new ones. foreach (RestrictionEntry entry in newEntries) { String key = entry.Key; if (KEY_BOOLEAN.Equals (key)) { entry.SelectedState = existingRestrictions.GetBoolean (KEY_BOOLEAN); } else if (KEY_CHOICE.Equals (key)) { if (existingRestrictions.ContainsKey (KEY_CHOICE)) { entry.SelectedString = existingRestrictions.GetString (KEY_CHOICE); } } else if (KEY_MULTI_SELECT.Equals (key)) { if (existingRestrictions.ContainsKey (KEY_MULTI_SELECT)) { entry.SetAllSelectedStrings(existingRestrictions.GetStringArray (key)); } } } var extra = new Bundle(); // This path demonstrates the use of a custom app restriction activity instead of standard // types. When a custom activity is set, the standard types will not be available under // app restriction settings. // // If your app has an existing activity for app restriction configuration, you can set it // up with the intent here. if (PreferenceManager.GetDefaultSharedPreferences (context) .GetBoolean (MainActivity.CUSTOM_CONFIG_KEY, false)) { var customIntent = new Intent(); customIntent.SetClass (context, typeof (CustomRestrictionsActivity)); extra.PutParcelable (Intent.ExtraRestrictionsIntent, customIntent); } extra.PutParcelableArrayList (Intent.ExtraRestrictionsList, newEntries); result.SetResult (Result.Ok, null, extra); result.Finish (); }
private void CreateRestrictions(Context context, PendingResult result, Bundle existingRestrictions) { // The incoming restrictions bundle contains key/value pairs representing existing app // restrictions for this package. In order to retain existing app restrictions, you need to // construct new restriction entries and then copy in any existing values for the new keys. List <IParcelable> newEntries = InitRestrictions(context); // If app restrictions were not previously configured for the package, create the default // restrictions entries and return them. if (existingRestrictions == null) { var extras = new Bundle(); extras.PutParcelableArrayList(Intent.ExtraRestrictionsList, newEntries); result.SetResult(Result.Ok, null, extras); result.Finish(); return; } // Retains current restriction settings by transferring existing restriction entries to // new ones. foreach (RestrictionEntry entry in newEntries) { String key = entry.Key; if (KEY_BOOLEAN.Equals(key)) { entry.SelectedState = existingRestrictions.GetBoolean(KEY_BOOLEAN); } else if (KEY_CHOICE.Equals(key)) { if (existingRestrictions.ContainsKey(KEY_CHOICE)) { entry.SelectedString = existingRestrictions.GetString(KEY_CHOICE); } } else if (KEY_MULTI_SELECT.Equals(key)) { if (existingRestrictions.ContainsKey(KEY_MULTI_SELECT)) { entry.SetAllSelectedStrings(existingRestrictions.GetStringArray(key)); } } } var extra = new Bundle(); // This path demonstrates the use of a custom app restriction activity instead of standard // types. When a custom activity is set, the standard types will not be available under // app restriction settings. // // If your app has an existing activity for app restriction configuration, you can set it // up with the intent here. if (PreferenceManager.GetDefaultSharedPreferences(context) .GetBoolean(MainActivity.CUSTOM_CONFIG_KEY, false)) { var customIntent = new Intent(); customIntent.SetClass(context, typeof(CustomRestrictionsActivity)); extra.PutParcelable(Intent.ExtraRestrictionsIntent, customIntent); } extra.PutParcelableArrayList(Intent.ExtraRestrictionsList, newEntries); result.SetResult(Result.Ok, null, extra); result.Finish(); }