public override bool Equals(object obj) { if (obj == null) { return(false); } if (this.GetType() != obj.GetType()) { return(false); } FCM account = (FCM)obj; return(this.device_id == account.device_id); }
private async Task SendRegistrationToServer(string token) { try { var fcmList = await GetDeviceIDFCM(); //string deviceID = Android.Provider.Settings.Secure.GetString(Android.App.Application.Context.ContentResolver, Android.Provider.Settings.Secure.AndroidId); string deviceID = CrossDeviceInfo.Current.Id; var fcmObject = new FCM(deviceID); var exists = fcmList.Contains(fcmObject); var dict = new Dictionary <string, string>(); dict.Add("name", ""); dict.Add("registration_id", token); dict.Add("device_id", deviceID); //dict.Add("acive", ); dict.Add("type", "android"); var client = new HttpClient(); if (exists) { var existingAccountIndex = fcmList.IndexOf(fcmObject); var existingAccount = fcmList[existingAccountIndex]; var req = new HttpRequestMessage(HttpMethod.Put, "https://lockec.pythonanywhere.com/api/devices/" + existingAccount.registration_id + "/") { Content = new FormUrlEncodedContent(dict) }; var response = await client.SendAsync(req).ConfigureAwait(false); } else { var req = new HttpRequestMessage(HttpMethod.Post, "https://lockec.pythonanywhere.com/api/devices/") { Content = new FormUrlEncodedContent(dict) }; var response = await client.SendAsync(req).ConfigureAwait(false); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); } }