//This procedure calls //not sure if im calling this right. //1) is it OK to pass in mainactivity like this? //2) any way to get a callback after they enable? (ie, to reload webview) //3) any way to delay the initial load of the webview until they hit the OK button to load fixity? //https://forums.xamarin.com/discussion/118189/gps-location-enable-in-xamarin-forms //https://stackoverflow.com/questions/33251373/turn-on-location-services-without-navigating-to-settings-page //https://stackoverflow.com/questions/43138788/ask-user-to-turn-on-location/43139125 //https://forums.xamarin.com/discussion/140325/how-to-check-every-time-for-gps-connectivity (code based on this) public async void turnOnGps(MainActivity activity) { try { //MainActivity activity = Xamarin.Forms.Context as MainActivity; GoogleApiClient googleApiClient = new GoogleApiClient.Builder(activity) .AddApi(LocationServices.API).Build(); googleApiClient.Connect(); LocationRequest locationRequest = LocationRequest.Create(); locationRequest.SetPriority(LocationRequest.PriorityHighAccuracy); locationRequest.SetInterval(10000); locationRequest.SetFastestInterval(10000 / 2); LocationSettingsRequest.Builder locationSettingsRequestBuilder = new LocationSettingsRequest.Builder() .AddLocationRequest(locationRequest); locationSettingsRequestBuilder.SetAlwaysShow(false); LocationSettingsResult locationSettingsResult = await LocationServices.SettingsApi.CheckLocationSettingsAsync( googleApiClient, locationSettingsRequestBuilder.Build()); if (locationSettingsResult.Status.StatusCode == LocationSettingsStatusCodes.ResolutionRequired) { locationSettingsResult.Status.StartResolutionForResult(activity, 0); } } catch (Java.Lang.Exception ex) { Xamarin.Forms.DependencyService.Get <IMessage>().LongAlert(ex.Message); //show error } }
public static GoogleApiClient ConfigureGoogleSignIn(Context context) { //if (context is IOnCompleteListener && context is GoogleApiClient.IConnectionCallbacks && context is GoogleApiClient.IOnConnectionFailedListener) if (context is LoginActivity) { //var onComplete = context as IOnCompleteListener; //var goooglConncectionCallBack = context as GoogleApiClient.IConnectionCallbacks; //var goooglConncectionFail = context as GoogleApiClient.IOnConnectionFailedListener; var LoginContext = (LoginActivity)context; GoogleSignInOptions gso = new GoogleSignInOptions .Builder(GoogleSignInOptions.DefaultSignIn) .RequestIdToken(context.GetString(Resource.String.server_client_id)) .RequestEmail() .Build(); var _googleApiClient = new GoogleApiClient .Builder(LoginContext) .EnableAutoManage(LoginContext, LoginContext).AddOnConnectionFailedListener(LoginContext) .AddApi(Auth.GOOGLE_SIGN_IN_API, gso) .AddConnectionCallbacks(LoginContext).Build(); return(_googleApiClient); } return(null); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); // Create your application here System.Diagnostics.Debug.WriteLine("In login page..."); SetContentView(Resource.Layout.Login); mGoogleSignIn = FindViewById <SignInButton>(Resource.Id.sign_in_button); Android.Widget.Button b2 = FindViewById <Android.Widget.Button>(Resource.Id.button1); b2.Click += delegate { StartActivity(typeof(register)); }; mGoogleSignIn.Click += mGoogleSignIn_Click; GoogleApiClient.Builder builder = new GoogleApiClient.Builder(this); builder.AddConnectionCallbacks(this); builder.AddOnConnectionFailedListener(this); builder.AddApi(PlusClass.API); builder.AddScope(PlusClass.ScopePlusProfile); builder.AddScope(PlusClass.ScopePlusLogin); //Build our IGoogleApiClient mGoogleApiClient = builder.Build(); }
} //singleton public void Initialize(Context context) { GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DefaultSignIn) .RequestEmail() .RequestProfile() .Build(); //_googleApiClient = new GoogleApiClient.Builder(context) // //.AddApi(Auth.GOOGLE_SIGN_IN_API, gso) // .AddConnectionCallbacks(this) // .AddOnConnectionFailedListener(this) // .AddApi(DriveClass.API).AddScope(new Scope(Scopes.DriveFile)) // .Build(); // //auth _googleApiClient = new GoogleApiClient.Builder(context) .AddConnectionCallbacks(this) .AddOnConnectionFailedListener(this) .AddApi(Auth.GOOGLE_SIGN_IN_API, gso) .Build(); if (!_googleApiClient.IsConnected) { _googleApiClient.Connect(); //logout: GoogleManager._googleApiClient.Disconnect(); } }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.Register); Button register_farmer = FindViewById <Button>(Resource.Id.button1); Button register_muc = FindViewById <Button>(Resource.Id.button2); GoogleApiClient.Builder builder = new GoogleApiClient.Builder(this); builder.AddConnectionCallbacks(this); builder.AddOnConnectionFailedListener(this); builder.AddApi(PlusClass.API); builder.AddScope(PlusClass.ScopePlusProfile); builder.AddScope(PlusClass.ScopePlusLogin); //Build our IGoogleApiClient mGoogleApiClient = builder.Build(); register_farmer.Click += delegate { user_type = 2; if (!mGoogleApiClient.IsConnecting) { mSignInClicked = true; ResolveSignInError(); } }; register_muc.Click += delegate { user_type = 3; if (!mGoogleApiClient.IsConnecting) { mSignInClicked = true; ResolveSignInError(); } }; }
private static GoogleApiClient BuildGoogleApiClient() { #if DEBUG GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DefaultSignIn) .RequestIdToken("59954122652-54snfl95i3cigj67phdjpvovvrokn4ec.apps.googleusercontent.com") .RequestEmail() .Build(); #else GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DefaultSignIn) .RequestIdToken("711636366543-0tmtrgmtp43d4q60c31alhur9j2m8ha2.apps.googleusercontent.com") .RequestEmail() .Build(); #endif var builder = new GoogleApiClient.Builder(CrossCurrentActivity.Current.Activity) .AddApi(Auth.GOOGLE_SIGN_IN_API, gso); if (CrossCurrentActivity.Current.Activity is GoogleApiClient.IConnectionCallbacks connectionCallbackHandler) { builder.AddConnectionCallbacks(connectionCallbackHandler); } if (CrossCurrentActivity.Current.Activity is GoogleApiClient.IOnConnectionFailedListener connectionFailedHandler) { builder.AddOnConnectionFailedListener(connectionFailedHandler); } return(builder.Build()); }
GoogleApiClient buildGoogleApiClient(bool useProfileScope) { var builder = new GoogleApiClient.Builder(this) .AddConnectionCallbacks(this) .AddOnConnectionFailedListener(this); var serverClientId = GetString(Resource.String.server_client_id); //if (!string.IsNullOrEmpty (serverClientId)) // builder.RequestServerAuthCode (serverClientId, this); if (useProfileScope) { builder.AddApi(PlusClass.API) .AddScope(PlusClass.ScopePlusProfile); } else { //var options = new PlusClass.PlusOptions.Builder ().AddActivityTypes (MomentUtil.ACTIONS).Build (); builder.AddApi(PlusClass.API) //, options) .AddScope(PlusClass.ScopePlusLogin); } return(builder.Build()); }
public IObservable <string> GetAuthToken() { lock (lockable) { if (isLoggingIn) { return(subject.AsObservable()); } isLoggingIn = true; subject = new Subject <string>(); var activity = Mvx.Resolve <IMvxAndroidCurrentTopActivity>().Activity as FragmentActivity; var signInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DefaultSignIn) .RequestIdToken("{TOGGL_DROID_GOOGLE_SERVICES_CLIENT_ID}") .RequestEmail() .Build(); var googleApiClient = new GoogleApiClient.Builder(activity) .EnableAutoManage(activity, onError) .AddApi(Auth.GOOGLE_SIGN_IN_API, signInOptions) .Build(); var intent = Auth.GoogleSignInApi.GetSignInIntent(googleApiClient); StartActivityForResult(googleSignInResult, intent); return(subject.AsObservable()); } }
public async void turnOnGps() { try { MainActivity activity = global::Xamarin.Forms.Forms.Context as MainActivity; GoogleApiClient googleApiClient = new GoogleApiClient.Builder(activity).AddApi(LocationServices.API).Build(); googleApiClient.Connect(); LocationRequest locationRequest = LocationRequest.Create(); locationRequest.SetPriority(LocationRequest.PriorityHighAccuracy); locationRequest.SetInterval(10000); locationRequest.SetFastestInterval(10000 / 2); LocationSettingsRequest.Builder locationSettingsRequestBuilder = new LocationSettingsRequest.Builder().AddLocationRequest(locationRequest); locationSettingsRequestBuilder.SetAlwaysShow(false); LocationSettingsResult locationSettingsResult = await LocationServices.SettingsApi.CheckLocationSettingsAsync( googleApiClient, locationSettingsRequestBuilder.Build()); if (locationSettingsResult.Status.StatusCode == LocationSettingsStatusCodes.ResolutionRequired) { locationSettingsResult.Status.StartResolutionForResult(activity, 0); } var result = await LocationServices.SettingsApi.CheckLocationSettingsAsync(googleApiClient, locationSettingsRequestBuilder.Build()); } catch (Exception ex) { } }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.login); //skip login //GoToMainPage(1); GoogleApiClient.Builder builder = new GoogleApiClient.Builder(this); builder.AddConnectionCallbacks(this); builder.AddOnConnectionFailedListener(this); builder.AddApi(PlusClass.API); builder.AddScope(PlusClass.ScopePlusProfile); builder.AddScope(PlusClass.ScopePlusLogin); googleApiClient = builder.Build(); etEmail = FindViewById <EditText>(Resource.Id.TextEmail); etPass = FindViewById <EditText>(Resource.Id.TextPass); btnOK = FindViewById <Button>(Resource.Id.buttonOk); btnGoogleSignIn = FindViewById <SignInButton>(Resource.Id.sign_in_button); btnOK.Click += BtnOK_Click; btnGoogleSignIn.Click += BtnGoogleSignIn_Click; }
public AndroidDatabaseProvider(Activity activity) { this.activity = activity; GoogleApiAvailability googleApiAvailability = GoogleApiAvailability.Instance; if (googleApiAvailability.IsGooglePlayServicesAvailable(activity) == ConnectionResult.Success) { string accountName; using (ISharedPreferences settings = activity.GetSharedPreferences(SETTINGS_NAME, FileCreationMode.Private)) { accountName = settings.GetString(SETTINGS_STRING_ACCOUNTNAME, string.Empty); } global::Android.Widget.Toast.MakeText(activity, "awdawd", Android.Widget.ToastLength.Short); GoogleApiClient.Builder builder = new GoogleApiClient.Builder(activity, this, this) .AddApi(GamesClass.API) .AddScope(GamesClass.ScopeGames) .AddApi(DriveClass.API) .AddScope(DriveClass.ScopeAppfolder); if (!string.IsNullOrEmpty(accountName)) { builder.SetAccountName(accountName); } _GoogleApiClient = builder.Build( ); _GoogleApiClient.Connect( ); } localStateDatabase = activity.GetSharedPreferences(LOCAL_COPY_STATE_NAME, FileCreationMode.Private); }
protected synchronized void buildGoogleApiClient() { mGoogleApiClient = new GoogleApiClient.Builder(this) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .addApi(LocationServices.API) .build(); }
static GoogleApiClient BuildApiClient() { var c = new GoogleApiClient.Builder(Application.Context). AddApi(LocationServices.API) .Build(); c.Connect(); return(c); }
public void BuildApiClient() { MClient = new GoogleApiClient.Builder(this) .AddApi(FitnessClass.HISTORY_API) .AddScope(FitnessClass.ScopeActivityRead) .AddScope(FitnessClass.ScopeLocationRead) .AddOnConnectionFailedListener(ConnectionFailed) .Build(); }
public void Register(Context context) { this.context = context; GoogleApiClient.Builder builder = new GoogleApiClient.Builder(context, this, this); builder.AddApi(DriveClass.API); builder.AddScope(DriveClass.ScopeFile); client = builder.Build(); }
private void ConfigurateGoogleSigin() { GoogleApiClient.Builder gBuilder = new GoogleApiClient.Builder(this); gBuilder.AddConnectionCallbacks(this); gBuilder.AddOnConnectionFailedListener(this); gBuilder.AddApi(PlusClass.API); gBuilder.AddScope(PlusClass.ScopePlusProfile); gBuilder.AddScope(PlusClass.ScopePlusLogin); oGoogleApiClient = gBuilder.Build(); }
public GoogleApiClient GetGoogleApiClient(AppCompatActivity activity, GoogleApiClient.IOnConnectionFailedListener listener) { this.activity = activity; mGoogleApiClient = new GoogleApiClient.Builder(Application.Context) .EnableAutoManage(this.activity, listener) .AddApi(Auth.GOOGLE_SIGN_IN_API, GetGoogleSignInOptions()) .Build(); return(mGoogleApiClient); }
private GoogleApiClient BuildApiClient() { GoogleApiClient client = new GoogleApiClient.Builder(this, this, this) .AddApi(LocationServices.API) .AddConnectionCallbacks(this) .AddOnConnectionFailedListener(this) .Build(); return(client); }
async void HandleMessage(IMessageEvent message) { try { Android.Util.Log.Info("WearIntegration", "Received Message"); var client = new GoogleApiClient.Builder(this) .AddApi(WearableClass.API) .Build(); var result = client.BlockingConnect(30, Java.Util.Concurrent.TimeUnit.Seconds); if (!result.IsSuccess) { return; } var path = message.Path; try { if (path.StartsWith(TweetsPath)) { var viewModel = new TwitterViewModel(); await viewModel.ExecuteLoadTweetsCommand(); var request = PutDataMapRequest.Create(TweetsPath + "/Answer"); var map = request.DataMap; var tweetMap = new List <DataMap>(); foreach (var tweet in viewModel.Tweets) { var itemMap = new DataMap(); itemMap.PutLong("CreatedAt", tweet.CreatedAt.Ticks); itemMap.PutString("ScreenName", tweet.ScreenName); itemMap.PutString("Text", tweet.Text); tweetMap.Add(itemMap); } map.PutDataMapArrayList("Tweets", tweetMap); map.PutLong("UpdatedAt", DateTime.UtcNow.Ticks); await WearableClass.DataApi.PutDataItem(client, request.AsPutDataRequest()); } } finally { client.Disconnect(); } } catch (Exception e) { Android.Util.Log.Error("WearIntegration", e.ToString()); } }
protected override async Task <bool> EnableDeviceLocationService() { var context = Forms.Context; var activity = (MainActivity)context; var listener = new ActivityResultListener(activity); var googleApiClient = new GoogleApiClient.Builder(activity).AddApi(LocationServices.API).Build(); googleApiClient.Connect(); var locationRequest = LocationRequest.Create(); locationRequest.SetPriority(LocationRequest.PriorityHighAccuracy); locationRequest.SetInterval(10000); locationRequest.SetFastestInterval(10000 / 2); var builder = new LocationSettingsRequest.Builder().AddLocationRequest(locationRequest); builder.SetAlwaysShow(true); var result = LocationServices.SettingsApi.CheckLocationSettings(googleApiClient, builder.Build()); result.SetResultCallback((LocationSettingsResult callback) => { switch (callback.Status.StatusCode) { case LocationSettingsStatusCodes.Success: { break; } case LocationSettingsStatusCodes.ResolutionRequired: { try { // Show the dialog by calling startResolutionForResult(), and check the result // in onActivityResult(). callback.Status.StartResolutionForResult(activity, REQUEST_CHECK_SETTINGS); } catch (IntentSender.SendIntentException e) { } break; } default: { // If all else fails, take the user to the android location settings activity.StartActivity(new Intent(Android.Provider.Settings.ActionLocationSourceSettings)); break; } } }); return(await listener.Task); }
private bool DisplayLocationSettingsRequest() { bool islocationOn = false; var googleApiClient = new GoogleApiClient.Builder(this).AddApi(LocationServices.API).Build(); googleApiClient.Connect(); var locationRequest = LocationRequest.Create(); locationRequest.SetPriority(LocationRequest.PriorityHighAccuracy); locationRequest.SetInterval(10000); locationRequest.SetFastestInterval(10000 / 2); var builder = new LocationSettingsRequest.Builder().AddLocationRequest(locationRequest); builder.SetAlwaysShow(true); var result = LocationServices.SettingsApi.CheckLocationSettings(googleApiClient, builder.Build()); result.SetResultCallback((LocationSettingsResult callback) => { switch (callback.Status.StatusCode) { case LocationSettingsStatusCodes.Success: { islocationOn = true; //DoStuffWithLocation(); break; } case LocationSettingsStatusCodes.ResolutionRequired: { try { // Show the dialog by calling startResolutionForResult(), and check the result // in onActivityResult(). callback.Status.StartResolutionForResult(this, 100); } catch (IntentSender.SendIntentException e) { } break; } default: { // If all else fails, take the user to the android location settings StartActivity(new Intent(Android.Provider.Settings.ActionLocationSourceSettings)); break; } } }); return(islocationOn); }
public async void OpenSettings() { LocationManager LM = (LocationManager)Android.App.Application.Context.GetSystemService(Context.LocationService); if (LM.IsProviderEnabled(LocationManager.GpsProvider) == false) { Context ctx = Android.App.Application.Context; p0 = Platform.CurrentActivity; //----------------------------------------------------------------------------------------------------------------- try { GoogleApiClient googleApiClient = new GoogleApiClient.Builder(ctx) .AddApi(LocationServices.API) .Build(); googleApiClient.Connect(); LocationRequest locationRequest = LocationRequest.Create() .SetPriority(LocationRequest.PriorityBalancedPowerAccuracy) .SetInterval(interval) .SetFastestInterval(fastestInterval); LocationSettingsRequest.Builder locationSettingsRequestBuilder = new LocationSettingsRequest.Builder() .AddLocationRequest(locationRequest); locationSettingsRequestBuilder.SetAlwaysShow(false); LocationSettingsResult locationSettingsResult = await LocationServices.SettingsApi.CheckLocationSettingsAsync(googleApiClient, locationSettingsRequestBuilder.Build()); if (locationSettingsResult.Status.StatusCode == LocationSettingsStatusCodes.ResolutionRequired) { locationSettingsResult.Status.StartResolutionForResult(p0, 0); } } catch (Exception exception) { // Log exception } //----------------------------------------------------------------------------------------------------------------- //ctx.StartActivity(new Intent(Android.Provider.Settings.ActionLocationSourceSettings).SetFlags(ActivityFlags.NewTask)); //Application.Context.StartActivity(new Android.Content.Intent(Android.Provider.Settings.ActionLocationSourceSettings)); } else { //this is handled in the PCL } }
private async Task OnDataChangedAsync(DataEventBuffer dataEvents) { if (localNodeId == null) { GoogleApiClient googleApiClient = new GoogleApiClient.Builder(this) .AddApi(WearableClass.API) .Build(); googleApiClient.Connect(); localNodeId = (await WearableClass.NodeApi.GetLocalNodeAsync(googleApiClient).ConfigureAwait(false)).Node.Id; } ISharedPreferences settings = string.IsNullOrEmpty(sharedPrefsName) ? PreferenceManager.GetDefaultSharedPreferences(this) : GetSharedPreferences(sharedPrefsName, FileCreationMode.Private); ISharedPreferencesEditor editor = settings.Edit(); IDictionary <string, object> allPrefs = settings.All; try { foreach (IDataEvent ev in dataEvents) { IDataItem dataItem = ev.DataItem; Android.Net.Uri uri = dataItem.Uri; var nodeId = uri.Host; if (nodeId.Equals(localNodeId)) { // Change originated on this device. continue; } if (uri.Path.StartsWith(DATA_SETTINGS_PATH)) { if (ev.Type == DataEvent.TypeDeleted) { DeleteItem(uri, editor, allPrefs); } else { SaveItem(dataItem, editor, allPrefs); } } } } finally { // We don't use Apply() because we don't know what thread we're on. editor.Commit(); } base.OnDataChanged(dataEvents); }
public FusedGeolocator() { //_manager = (LocationManager)Application.Context.GetSystemService(Context.LocationService); //_providers = _manager.GetProviders(false).Where(s => s != LocationManager.PassiveProvider).ToArray(); mGoogleApiClient = new GoogleApiClient.Builder((Activity)Xamarin.Forms.Forms.Context) .AddApi(LocationServices.API) .AddConnectionCallbacks(this) .AddOnConnectionFailedListener(this) .Build(); mGoogleApiClient.Connect(); }
public GoogleManager() { Instance = this; GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DefaultSignIn).RequestEmail().Build(); _googleApiClient = new GoogleApiClient.Builder(Android.App.Application.Context) .AddConnectionCallbacks(this) .AddOnConnectionFailedListener(this) .AddApi(Auth.GOOGLE_SIGN_IN_API, gso) .AddScope(new Scope(Scopes.Profile)) .Build(); }
public GoogleApiClient GoogleLogin(Context context, FragmentActivity fragmentActivity, GoogleApiClient.IOnConnectionFailedListener onConnectionFailedListener, GoogleApiClient.IConnectionCallbacks onconnectionCallbacks) { GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DefaultSignIn) .RequestEmail() .Build(); GoogleApiClient mgoogleApiClient = new GoogleApiClient.Builder(context) .EnableAutoManage(fragmentActivity, onConnectionFailedListener) .AddApi(Auth.GOOGLE_SIGN_IN_API, gso) .AddConnectionCallbacks(onconnectionCallbacks) .Build(); return(mgoogleApiClient); }
public static void CreateBuilder() { var googleCallbacks = new GoogleCallback(); Builder = new GoogleApiClient.Builder(Forms.Context); Builder.AddConnectionCallbacks(googleCallbacks); Builder.AddOnConnectionFailedListener(googleCallbacks); Builder.AddApi(PlusClass.API); Builder.AddScope(PlusClass.ScopePlusLogin); Builder.AddScope(PlusClass.ScopePlusProfile); MyGoogleApiClient = Builder.Build(); }
/// <summary> /// Initializes a new instance of the <see cref="GoogleService" /> class. /// </summary> public GoogleService() { Instance = this; var gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DefaultSignIn) .RequestIdToken("526829940303-4p7sa6kh8j5ojcb8gjnf6i3t4sind0sr.apps.googleusercontent.com").RequestId().RequestEmail().Build(); //var gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DefaultSignIn) // .RequestId().RequestEmail().Build(); GoogleApiClient = new GoogleApiClient.Builder(((MainActivity)_context).ApplicationContext) .AddConnectionCallbacks(this).AddOnConnectionFailedListener(this).AddApi(Auth.GOOGLE_SIGN_IN_API, gso) .AddScope(new Scope(Scopes.Profile)).Build(); }
internal GoogleClientManager() { GoogleSignInOptions googleSignInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DefaultSignIn) .RequestEmail() .Build(); GoogleApiClient = new GoogleApiClient.Builder(Application.Context) .AddConnectionCallbacks(this) .AddOnConnectionFailedListener(this) .AddApi(Auth.GOOGLE_SIGN_IN_API, googleSignInOptions) .AddScope(new Scope(Scopes.Profile)) .Build(); }
private void CreateClient() { var builder = new GoogleApiClient.Builder(activity, this, this); builder.AddApi(GamesClass.API); builder.AddScope(GamesClass.ScopeGames); if (ViewForPopups != null) { builder.SetViewForPopups(ViewForPopups); } client = builder.Build(); }
public FireAuth() { Instance = this; var gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DefaultSignIn) .RequestIdToken("738002101933-57crr6hvomm49gasqaj3fa5tnrshsdd7.apps.googleusercontent.com") .RequestEmail().Build(); GoogleApiClient = new GoogleApiClient.Builder(((MainActivity)Forms.Context).ApplicationContext) .AddConnectionCallbacks(this) .AddOnConnectionFailedListener(this) .AddApi(Auth.GOOGLE_SIGN_IN_API, gso) .AddScope(new Scope(Scopes.Profile)) .Build(); }
protected override void OnHandleIntent (Intent intent) { if (intent.Action.Equals (ACTION_RESET_QUIZ)) { var google_api_client = new GoogleApiClient.Builder (this) .AddApi (WearableClass.API) .Build (); ConnectionResult result = google_api_client.BlockingConnect (Constants.CONNECT_TIMEOUT_MS, TimeUnit.Milliseconds); if (!result.IsSuccess) { Log.Error (TAG, "QuizListenerService failed to connect to GoogleApiClient."); return; } var nodes = WearableClass.NodeApi.GetConnectedNodes (google_api_client).Await ().JavaCast<INodeApiGetConnectedNodesResult>(); foreach (INode node in nodes.Nodes) { WearableClass.MessageApi.SendMessage (google_api_client, node.Id, Constants.RESET_QUIZ_PATH, new byte[0]); } } }
public override void OnDataChanged(DataEventBuffer eventBuffer) { var events = FreezableUtils.FreezeIterable (eventBuffer); eventBuffer.Close (); var google_api_client = new GoogleApiClient.Builder (this) .AddApi (WearableClass.API) .Build (); var connectionResult = google_api_client.BlockingConnect (Constants.CONNECT_TIMEOUT_MS, TimeUnit.Milliseconds); if (!connectionResult.IsSuccess) { Log.Error (TAG, "QuizListenerService failed to connect to GoogleApiClient."); return; } foreach (var ev in events) { var e = ((Java.Lang.Object)ev).JavaCast<IDataEvent> (); if (e.Type == DataEvent.TypeChanged) { var dataItem = e.DataItem; var dataMap = DataMapItem.FromDataItem (dataItem).DataMap; if (dataMap.GetBoolean (Constants.QUESTION_WAS_ANSWERED) || dataMap.GetBoolean (Constants.QUESTION_WAS_DELETED)) { continue; } string question = dataMap.GetString (Constants.QUESTION); int questionIndex = dataMap.GetInt (Constants.QUESTION_INDEX); int questionNum = questionIndex + 1; string[] answers = dataMap.GetStringArray (Constants.ANSWERS); int correctAnswerIndex = dataMap.GetInt (Constants.CORRECT_ANSWER_INDEX); Intent deleteOperation = new Intent (this, typeof(DeleteQuestionService)); deleteOperation.SetData (dataItem.Uri); PendingIntent deleteIntent = PendingIntent.GetService (this, 0, deleteOperation, PendingIntentFlags.UpdateCurrent); //first page of notification contains question as Big Text. var bigTextStyle = new Notification.BigTextStyle () .SetBigContentTitle (GetString (Resource.String.question, questionNum)) .BigText (question); var builder = new Notification.Builder (this) .SetStyle (bigTextStyle) .SetSmallIcon (Resource.Drawable.ic_launcher) .SetLocalOnly (true) .SetDeleteIntent (deleteIntent); //add answers as actions var wearableOptions = new Notification.WearableExtender (); for (int i = 0; i < answers.Length; i++) { Notification answerPage = new Notification.Builder (this) .SetContentTitle (question) .SetContentText (answers [i]) .Extend (new Notification.WearableExtender () .SetContentAction (i)) .Build (); bool correct = (i == correctAnswerIndex); var updateOperation = new Intent (this, typeof(UpdateQuestionService)); //Give each intent a unique action. updateOperation.SetAction ("question_" + questionIndex + "_answer_" + i); updateOperation.SetData (dataItem.Uri); updateOperation.PutExtra (UpdateQuestionService.EXTRA_QUESTION_INDEX, questionIndex); updateOperation.PutExtra (UpdateQuestionService.EXTRA_QUESTION_CORRECT, correct); var updateIntent = PendingIntent.GetService (this, 0, updateOperation, PendingIntentFlags.UpdateCurrent); Notification.Action action = new Notification.Action.Builder ( (int)question_num_to_drawable_id.Get (i), (string)null, updateIntent) .Build (); wearableOptions.AddAction (action).AddPage (answerPage); } builder.Extend (wearableOptions); Notification notification = builder.Build (); ((NotificationManager)GetSystemService (NotificationService)) .Notify (questionIndex, notification); } else if (e.Type == DataEvent.TypeDeleted) { Android.Net.Uri uri = e.DataItem.Uri; //URIs are in the form of "/question/0", "/question/1" etc. //We use the question index as the notification id. int notificationId = Java.Lang.Integer.ParseInt (uri.LastPathSegment); ((NotificationManager)GetSystemService (NotificationService)) .Cancel (notificationId); } ((NotificationManager)GetSystemService (NotificationService)) .Cancel (QUIZ_REPORT_NOTIF_ID); } google_api_client.Disconnect (); }
GoogleApiClient buildGoogleApiClient (bool useProfileScope) { var builder = new GoogleApiClient.Builder (this) .AddConnectionCallbacks (this) .AddOnConnectionFailedListener (this); var serverClientId = GetString (Resource.String.server_client_id); if (!string.IsNullOrEmpty (serverClientId)) builder.RequestServerAuthCode (serverClientId, this); if (useProfileScope) { builder.AddApi (PlusClass.API) .AddScope (PlusClass.ScopePlusProfile); } else { builder.AddApi (PlusClass.API, new PlusClass.PlusOptions.Builder () .AddActivityTypes (MomentUtil.ACTIONS).Build ()) .AddScope (PlusClass.ScopePlusLogin); } return builder.Build (); }
private void CreateClient() { // did we log in with a player id already? If so we don't want to ask which account to use var settings = this.activity.GetSharedPreferences ("googleplayservicessettings", FileCreationMode.Private); var id = settings.GetString ("playerid", String.Empty); var builder = new GoogleApiClient.Builder (activity, this, this); builder.AddApi (Android.Gms.Games.GamesClass.API); builder.AddScope (Android.Gms.Games.GamesClass.ScopeGames); builder.SetGravityForPopups ((int)GravityForPopups); if (ViewForPopups != null) builder.SetViewForPopups (ViewForPopups); if (!string.IsNullOrEmpty (id)) { builder.SetAccountName (id); } client = builder.Build (); }