private async Task <ContactList> GetContactListAsync(ContactStore store) { ContactList contactList; var contactsList = await store.FindContactListsAsync(); if (contactsList.Count == 0) { contactList = await store.CreateContactListAsync("Unigram"); contactList.OtherAppWriteAccess = ContactListOtherAppWriteAccess.None; await contactList.SaveAsync(); } else { contactList = contactsList[0]; if (contactList.OtherAppWriteAccess != ContactListOtherAppWriteAccess.None) { contactList.OtherAppWriteAccess = ContactListOtherAppWriteAccess.None; await contactList.SaveAsync(); } } return(contactList); }
/// <summary> /// Check if contact exists /// </summary> /// <param name="user">User to check</param> /// <returns>True if the user does not exist</returns> private async Task <bool> CheckContact(User user) { // Intialize store if not done if (store == null) { store = await Windows.ApplicationModel.Contacts.ContactManager.RequestStoreAsync(ContactStoreAccessType.AppContactsReadWrite); } if (store == null) { // Unavailable, call it quits return(true); } ContactList contactList; // Get contact lists for Discord IReadOnlyList <ContactList> contactLists = await store.FindContactListsAsync(); if (contactLists.Count == 0) { contactList = await store.CreateContactListAsync("Discord"); } else { contactList = contactLists[0]; } // Get user var returnval = await contactList.GetContactFromRemoteIdAsync(user.Id); // If user is null, return true return(returnval != null); }
public async Task InserNewContact(string firstName, string lastName, string phone, string email) { var contactInfo = new Contact { FirstName = firstName, LastName = lastName }; contactInfo.Phones.Add(new ContactPhone() { Number = phone }); contactInfo.Emails.Add(new ContactEmail() { Address = email }); ContactStore allAccessStore = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AllContactsReadOnly); var contactLists = await allAccessStore.FindContactListsAsync(); string contactListId = string.Empty; if (contactLists.Count != 0) { contactListId = contactLists.FirstOrDefault().Id; return; } var contactList = await allAccessStore.GetContactListAsync(contactListId); await contactList.SaveContactAsync(contactInfo); }
private async Task <ContactList> GetContactListAsync() { ContactStore store = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AppContactsReadWrite); // Find the contact list by name. (GetContactListAsync looks up a contact list by its ID.) IReadOnlyList <ContactList> lists = await store.FindContactListsAsync(); ContactList sampleList = null; foreach (ContactList list in lists) { if (list.DisplayName == Constants.ContactListName) { sampleList = list; break; } } if (sampleList == null) { sampleList = await store.CreateContactListAsync(Constants.ContactListName); } return(sampleList); }
public static async Task <string> GetNameFromRemotId(string remotID) { if (string.IsNullOrEmpty(remotID)) { return("Unknown"); } ContactList contactList; { ContactStore store = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AppContactsReadWrite); IReadOnlyList <ContactList> contactLists = await store.FindContactListsAsync(); if (contactLists.Count > 0) { contactList = contactLists[0]; } else { return("Unknown"); } } Contact contact = await contactList.GetContactFromRemoteIdAsync(remotID); if (contact != null) { return(contact.Name); } return("Unknown"); }
public async Task <bool> DeleteContact(Contact contact) { try { ContactStore allAccessStore = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AllContactsReadOnly); var contactLists = await allAccessStore.FindContactListsAsync(); string contactListId = string.Empty; if (contactLists.Count != 0) { contactListId = contactLists.FirstOrDefault().Id; return(false); } var contactList = await allAccessStore.GetContactListAsync(contactListId); await contactList.DeleteContactAsync(contact); return(true); } catch { return(false); } }
public async Task <List <string> > getContacts() { List <string> listResults = new List <string>(); ContactStore store = null; IReadOnlyList <ContactList> list = null; ContactReader reader = null; ContactBatch batch = null; // *** This RequestStoreAsync() call is where the exception is thrown. All the cases below have the same issue. *** //store = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AllContactsReadWrite); //store = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AppContactsReadWrite); store = await ContactManager.RequestStoreAsync(); list = await store.FindContactListsAsync(); foreach (ContactList contactList in list) { reader = contactList.GetContactReader(); batch = await reader.ReadBatchAsync(); foreach (Contact contact in batch.Contacts) { string fullname = contact.FullName; //+ ", " + contact.Name;// + ", " + contact.Emails.First().Address; listResults.Add(fullname); DisplayContact dc = new DisplayContact(contact); vDisplayContact.Add(dc); } } return(listResults); }
private async void DeleteTestContacts() { ContactList contactList = null; ContactStore store = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AppContactsReadWrite); if (null != store) { IReadOnlyList <ContactList> contactLists = await store.FindContactListsAsync(); if (0 < contactLists.Count) { contactList = contactLists[0]; } } if (null != contactList) { await contactList.DeleteAsync(); rootPage.NotifyUser("Sample data deleted.", NotifyType.StatusMessage); } else { rootPage.NotifyUser("Could not delete sample data.", NotifyType.ErrorMessage); } }
/// <summary> /// Load contact list /// </summary> /// <returns>Contact list</returns> private async Task <ContactList> GetContactList() { // If contact list is already determined, just return it if (contactList == null) { // Initialize contact store store = await Windows.ApplicationModel.Contacts.ContactManager.RequestStoreAsync(ContactStoreAccessType.AppContactsReadWrite); if (store == null) { // Unavailable, call it quits return(null); } // Get contact list IReadOnlyList <ContactList> contactLists = await store.FindContactListsAsync(); if (contactLists.Count == 0) { contactList = await store.CreateContactListAsync("Discord"); } else { contactList = contactLists[0]; } } // Return contact list return(contactList); }
private async void AddContact(Contact contact) { ContactStore contactstore = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AllContactsReadWrite); IReadOnlyList <ContactList> contactLists = await contactstore.FindContactListsAsync(); ContactList lists2 = null; //if there is no contact list we create one if (contactLists.Count == 0) { try { lists2 = await contactstore.CreateContactListAsync("MyList"); } catch (Exception ex) { MessageBox.Show("1:\n" + ex.ToString()); Console.WriteLine(ex); } } //otherwise if there is one then we reuse it else { foreach (var c in contactLists) { if (c.DisplayName == "MyList") { lists2 = c; break; } } if (lists2 == null) { try { lists2 = await contactstore.CreateContactListAsync("MyList"); } catch (Exception ex) { //MessageBox.Show("2:\n" + ex.ToString()); AddContact2(contact); return; } } } if (lists2 != null) { await lists2.SaveContactAsync(contact); return; } else { MessageBox.Show("cannot find ContactList MyList!"); } }
private async Task CleanUpContactListAsync() { if (ContactStore != null) { var contactLists = await ContactStore.FindContactListsAsync(); ContactList = (from c in contactLists where c.DisplayName == Constants.CONTACT_LIST_NAME select c).SingleOrDefault(); if (ContactList != null) { await ContactList.DeleteAsync(); } } }
private async Task <ContactList> GetContactListAsync() { ContactStore store = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AppContactsReadWrite); IReadOnlyList <ContactList> contactLists = await store.FindContactListsAsync(); ContactList sampleList = contactLists.FirstOrDefault(list => list.DisplayName.Equals(Constants.ContactListName)); if (sampleList == null) { sampleList = await store.CreateContactListAsync(Constants.ContactListName); } return(sampleList); }
private async Task <ContactList> GetContactListAsync(ContactStore store) { ContactList contactList; var contactsList = await store.FindContactListsAsync(); if (contactsList.Count == 0) { contactList = await store.CreateContactListAsync("Unigram"); } else { contactList = contactsList[0]; } return(contactList); }
private async Task <bool> saveContactToAddressBook(JObject c) { ContactStore store = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AppContactsReadWrite); string defaultListName = "myPrivateList"; /* Search for lists in contact list */ var lists = await store.FindContactListsAsync(); ContactList list = lists.FirstOrDefault((x) => x.DisplayName == "myPrivateList"); if (list == null) { list = await store.CreateContactListAsync(defaultListName); list.OtherAppReadAccess = ContactListOtherAppReadAccess.Full; list.OtherAppWriteAccess = ContactListOtherAppWriteAccess.SystemOnly; await list.SaveAsync(); } if (c["name"] != null) { Contact contact = new Contact(); contact.Name = c.Value <string>("name"); if (c["email"] != null) { contact.Emails.Add(new ContactEmail() { Kind = ContactEmailKind.Work, Address = c.Value <string>("email") }); } if (c["phone"] != null) { contact.Phones.Add(new ContactPhone() { Kind = ContactPhoneKind.Mobile, Number = c.Value <string>("phone") }); } await list.SaveContactAsync(contact); return(true); } else { return(false); } }
async private void AddContact() { ContactStore store = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AppContactsReadWrite); var lists = await store.FindContactListsAsync(); ContactList list = lists.FirstOrDefault((x) => x.DisplayName == "myPrivateList"); if (list == null) { list = await store.CreateContactListAsync("myPrivateList"); list.OtherAppReadAccess = ContactListOtherAppReadAccess.Full; list.OtherAppWriteAccess = ContactListOtherAppWriteAccess.SystemOnly; await list.SaveAsync(); } Contact contact = new Contact(); contact.Name = "Ocio fast food"; contact.Websites.Add(new ContactWebsite() { Description = "Sito web", RawValue = "https://www.facebook.com/ocioivrea/", Uri = new Uri("https://www.facebook.com/ocioivrea/") }); contact.Addresses.Add(new ContactAddress() { StreetAddress = "Corso Nigra 67", Description = "Indirizzo", Country = "Italia", Kind = ContactAddressKind.Work, Locality = "Ivrea", PostalCode = "10015", Region = "TO" }); var appInstalledFolder = Windows.ApplicationModel.Package.Current.InstalledLocation; var assets = await appInstalledFolder.GetFolderAsync("Assets"); var imageFile = await assets.GetFileAsync("StoreLogo.backup.png"); contact.SourceDisplayPicture = imageFile; contact.Phones.Add(new ContactPhone() { Kind = ContactPhoneKind.Work, Number = PHONE_NUMBER }); await list.SaveContactAsync(contact); var dialog = new MessageDialog("Contatto inserito. Grazie!"); await dialog.ShowAsync(); }
/// <summary> /// Get the ContactList for this app /// </summary> private async Task <ContactList> _GetContactListAsync() { // Get the contact store and the contact lists that are already present ContactStore store = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AppContactsReadWrite); IReadOnlyList <ContactList> contactLists = await store.FindContactListsAsync(); // Find the contact list that belongs to this app ContactList contactList = contactLists. FirstOrDefault(p => p.DisplayName == cContactListName); // Create the contact list if it is not present if (contactList == null) { contactList = await store.CreateContactListAsync(cContactListName); } return(contactList); }
private async Task <ContactList> GetAsync() { ContactList result = null; ContactStore store = await Store(); if (store != null) { IReadOnlyList <ContactList> list = await store.FindContactListsAsync(); if (list.Count == 0) { result = await store.CreateContactListAsync(contacts_list); } else { result = list.FirstOrDefault(s => s.DisplayName == contacts_list); } } return(result); }
private static async Task <ContactList> GetContactList() { ContactStore store = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AppContactsReadWrite); if (null == store) { return(null); } ContactList contactList; IReadOnlyList <ContactList> contactLists = await store.FindContactListsAsync(); if (0 == contactLists.Count) { contactList = await store.CreateContactListAsync("AsusRouterList"); } else { contactList = contactLists[0]; } return(contactList); }
private async Task InitializeContactListAsync() { if (ContactStore == null) { throw new Exception("Unable to get contacts store"); } var contactLists = await ContactStore.FindContactListsAsync(); ContactList = (from c in contactLists where c.DisplayName == Constants.CONTACT_LIST_NAME select c).SingleOrDefault(); if (ContactList == null) { ContactList = await ContactStore.CreateContactListAsync(Constants.CONTACT_LIST_NAME); ContactList.OtherAppReadAccess = ContactListOtherAppReadAccess.Limited; await ContactList.SaveAsync(); } ContactList.ContactChanged += _contactList_ContactChanged; ContactList.ChangeTracker.Enable(); }
private async Task <ContactList> _GetContactList() { ContactStore store = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AppContactsReadWrite); if (null == store) { rootPage.NotifyUser("Unable to get a contacts store.", NotifyType.ErrorMessage); return(null); } ContactList contactList; IReadOnlyList <ContactList> contactLists = await store.FindContactListsAsync(); if (0 == contactLists.Count) { contactList = await store.CreateContactListAsync("TestContactList"); } else { contactList = contactLists[0]; } return(contactList); }
private async void DoneContactClick(object sender, RoutedEventArgs e) { var contact = new Windows.ApplicationModel.Contacts.Contact(); contact.FirstName = name; ContactEmail email = new ContactEmail(); email.Address = mail; email.Kind = ContactEmailKind.Other; contact.Emails.Add(email); ContactPhone phone = new ContactPhone(); phone.Number = number; phone.Kind = ContactPhoneKind.Mobile; contact.Phones.Add(phone); ContactStore store = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AppContactsReadWrite); ContactList contactList; IReadOnlyList <ContactList> contactLists = await store.FindContactListsAsync(); if (0 == contactLists.Count) { contactList = await store.CreateContactListAsync("TestContactList"); } else { contactList = contactLists[0]; } await contactList.SaveContactAsync(contact); }
public static async void SyncContacts() { ContactList contactList; //CleanUp { ContactStore store = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AppContactsReadWrite); IReadOnlyList <ContactList> contactLists = await store.FindContactListsAsync(); if (contactLists.Count > 0) { await contactLists[0].DeleteAsync(); } contactList = await store.CreateContactListAsync("Lite Messenger"); } ContactAnnotationList annotationList; { ContactAnnotationStore annotationStore = await ContactManager.RequestAnnotationStoreAsync(ContactAnnotationStoreAccessType.AppAnnotationsReadWrite); IReadOnlyList <ContactAnnotationList> annotationLists = await annotationStore.FindAnnotationListsAsync(); if (annotationLists.Count > 0) { await annotationLists[0].DeleteAsync(); } annotationList = await annotationStore.CreateAnnotationListAsync(); } String appId = "4a6ce7f5-f418-4ba8-8836-c06d77ab735d_g91sr9nghxvmm!App"; foreach (var chatHeader in Names) { //if (chatHeader.IsGroup) // continue; Contact contact = new Contact { FirstName = chatHeader.Name, RemoteId = chatHeader.Href }; await contactList.SaveContactAsync(contact); ContactAnnotation annotation = new ContactAnnotation { ContactId = contact.Id, RemoteId = chatHeader.Href, SupportedOperations = ContactAnnotationOperations.Message }; if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 5)) { annotation.ProviderProperties.Add("ContactPanelAppID", appId); annotation.SupportedOperations = ContactAnnotationOperations.Message | ContactAnnotationOperations.ContactProfile; } await annotationList.TrySaveAnnotationAsync(annotation); } }
private async void AddContact(string firstName, string lastName) { /// https://docs.microsoft.com/en-us/windows/uwp/contacts-and-calendar/integrating-with-contacts /// https://stackoverflow.com/questions/34647386/windows-phone-10-is-possible-to-edit-add-new-contact-programmatically-in-wind ContactStore contactstore = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AllContactsReadWrite); IReadOnlyList <ContactList> contactLists = await contactstore.FindContactListsAsync(); ContactList lists2 = await contactstore.GetContactListAsync("24,d,d"); if (lists2 != null) { var contact1 = new Contact(); contact1.FirstName = firstName; contact1.LastName = lastName; await lists2.SaveContactAsync(contact1); return; } ContactList contactList = null; //if there is no contact list we create one if (contactLists.Count == 0) { try { contactList = await contactstore.CreateContactListAsync("MyList"); } catch (Exception ex) { Console.WriteLine(ex); } } //otherwise if there is one then we reuse it else { foreach (var c in contactLists) { if (c.DisplayName == "MyList") { contactList = c; break; } } } var contact = new Contact(); contact.FirstName = "Bob"; contact.LastName = "Doe"; ContactEmail email = new ContactEmail(); email.Address = "*****@*****.**"; email.Kind = ContactEmailKind.Other; contact.Emails.Add(email); await contactList.SaveContactAsync(contact); }