コード例 #1
0
        private async void BtnShareMail_Click(object sender, RoutedEventArgs e)
        {
            if (txtNom.Text != "" || txtPrenom.Text != "")
            {
                string        message       = "Bonjour, " + txtNom.Text + " " + txtPrenom.Text + " vous informe de sa participation à GeoDrapeau et que son score est de " + lblScore.Text + " points. \nSi vous pensez faire mieux, venez relever le défi.\n\nL'équipe de GeoDrapeau vous remercie.";
                ContactPicker contactPicker = new ContactPicker();
                Contact       contact       = await contactPicker.PickContactAsync();

                ContactStore contactStore = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AllContactsReadOnly);

                if (contact != null)
                {
                    Contact real = await contactStore.GetContactAsync(contact.Id);

                    EmailMessage emailMessage = new EmailMessage();
                    emailMessage.To.Add(new EmailRecipient(real.Emails.FirstOrDefault <Windows.ApplicationModel.Contacts.ContactEmail>().Address));
                    emailMessage.Subject = "GeoDrapeau Score" + ApplicationView.GetForCurrentView().Title.ToString().Trim();
                    emailMessage.Body    = message;

                    await EmailManager.ShowComposeNewEmailAsync(emailMessage);
                }
            }
            else
            {
                message();
            }
        }
コード例 #2
0
        private async void btnPickContact_Click(object sender, RoutedEventArgs e)
        {
            ContactPicker contactPicker = new ContactPicker();

            // 指定需要选取的联系人的字段
            contactPicker.DesiredFieldsWithContactFieldType.Add(ContactFieldType.Email);
            contactPicker.DesiredFieldsWithContactFieldType.Add(ContactFieldType.PhoneNumber);

            // 启动联系人选取器,以选择一个联系人
            Contact contact = await contactPicker.PickContactAsync();

            if (contact != null)
            {
                lblMsg.Text += string.Format("name:{0}", contact.Name);
                lblMsg.Text += Environment.NewLine;
                lblMsg.Text += string.Format("id:{0}", contact.Id);
                lblMsg.Text += Environment.NewLine;

                foreach (ContactEmail email in contact.Emails)
                {
                    lblMsg.Text += string.Format("email kind:{0}, email address:{1}", email.Kind, email.Address);
                    lblMsg.Text += Environment.NewLine;
                }

                foreach (ContactPhone phone in contact.Phones)
                {
                    lblMsg.Text += string.Format("phone kind:{0}, phone number:{1}, phone description:{2}", phone.Kind, phone.Number, phone.Description);
                    lblMsg.Text += Environment.NewLine;
                }


                ContactStore contactStore = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AllContactsReadOnly);

                // 通过 ContactStore 和联系人 id 可以获取到联系人的完整信息(需要配置 <Capability Name = "contacts" />)
                Contact realContact = await contactStore.GetContactAsync(contact.Id);

                // 通过 ContactStore 也是可以拿到全部联系人信息的,这部分知识点以后再写
                // IReadOnlyList<Contact> contacts = await contactStore.FindContactsAsync();

                // 显示联系人的图片(只通过 ContactPicker 是获取不到的)
                IRandomAccessStreamReference imageStreamRef = realContact.SmallDisplayPicture;
                if (imageStreamRef != null)
                {
                    IRandomAccessStream imageStream = await imageStreamRef.OpenReadAsync();

                    BitmapImage bitmapImage = new BitmapImage();
                    bitmapImage.SetSource(imageStream);
                    imgThumbnail.Source = bitmapImage;
                }
            }
            else
            {
                lblMsg.Text += "取消了";
                lblMsg.Text += Environment.NewLine;
            }
        }
コード例 #3
0
        public async Task <string> GetRemoteIdForContactIdAsync(string contactId)
        {
            var fullContact = await ContactStore.GetContactAsync(contactId);

            var contactAnnotations = await ContactAnnotationStore.FindAnnotationsForContactAsync(fullContact);

            if (contactAnnotations.Count >= 0)
            {
                return(contactAnnotations[0].RemoteId);
            }

            return(string.Empty);
        }
コード例 #4
0
ファイル: ContactsViewModel.cs プロジェクト: ice0/test
        /// <summary>
        /// Processes the open contact event
        /// </summary>
        public async void ProcessOpenContactAsync(ContactItem contact)
        {
            if (store == null)
            {
                //Shouldn't happen, and I don't want to deal with opening the store in multiple locations
                await LoadContactsFromStoreAsync();

                return;
            }
            Contact c = await store.GetContactAsync(contact.ContactId);

            ContactManager.ShowFullContactCard(c, new FullContactCardOptions());
        }
コード例 #5
0
ファイル: Shell.xaml.cs プロジェクト: cbhacking/Chat
        private async void HandleArguments(ProtocolActivatedEventArgs args)
        {
            Uri    uri           = args.Uri;
            string unescpateduri = Uri.UnescapeDataString(uri.Query);
            var    contactid     = unescpateduri.Replace("?ContactRemoteIds=", "");

            if (uri.Scheme == "ms-ipmessaging")
            {
                ContactStore store = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AppContactsReadWrite);

                Contact contact = await store.GetContactAsync(contactid);

                MainFrame.Navigate(typeof(ComposePage), contact);
            }
        }
コード例 #6
0
        private async void SendSMSButton_Tapped(object sender, TappedRoutedEventArgs e)
        {
            ContactPicker contactPicker = new ContactPicker();
            Contact       contact       = await contactPicker.PickContactAsync();

            // You need to add required capabilities in your App manifest file for access contact list.
            ContactStore contactStore = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AllContactsReadOnly);

            if (contact != null)
            {
                // Get Selected Contact
                Contact realContact = await contactStore.GetContactAsync(contact.Id);

                SendSMS(realContact, "This is test SMS.");
            }
        }
コード例 #7
0
        public static async Task <string> GetRemoteIdForContactIdAsync(Contact contactId)
        {
            ContactStore store = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AppContactsReadWrite);

            var fullContact = await store.GetContactAsync(contactId.Id);

            ContactAnnotationStore annotationStore = await ContactManager.RequestAnnotationStoreAsync(ContactAnnotationStoreAccessType.AppAnnotationsReadWrite);

            var contactAnnotations = await annotationStore.FindAnnotationsForContactAsync(fullContact);

            if (contactAnnotations.Count > 0)
            {
                return(contactAnnotations[0].RemoteId);
            }

            return(string.Empty);
        }
コード例 #8
0
        public async Task InitializePageAsync()
        {
            if (fullContact == null)
            {
                ContactStore store = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AppContactsReadWrite);

                try
                {
                    fullContact = await store.GetContactAsync(lightContact.Id);
                }
                catch
                {
                    // User denied access to the contact database.
                }
            }

            if (fullContact != null)
            {
                // Now that we have a full Contact object, we can do richer operations such as querying the display name
                this.contactName.Text = fullContact.DisplayName;

                // This is the remoteId that your app annotated the contact with on creation
                this.remoteId.Text = _appContactId = await GetRemoteIdForContactAsync(fullContact);

                if (RequestContactAccessPanel.Visibility == Visibility.Visible)
                {
                    Window.Current.Activated            -= OnWindowActivated;
                    ContactHistoryPanel.Visibility       = Visibility.Visible;
                    RequestContactAccessPanel.Visibility = Visibility.Collapsed;
                }
            }
            else
            {
                // Prompt the user to grant access to contacts.
                if (RequestContactAccessPanel.Visibility == Visibility.Collapsed)
                {
                    ContactHistoryPanel.Visibility       = Visibility.Collapsed;
                    RequestContactAccessPanel.Visibility = Visibility.Visible;

                    // Re-check each time we regain activation.
                    Window.Current.Activated += OnWindowActivated;
                }
            }
        }
コード例 #9
0
        private async Task <BitmapImage> GetPhoto(ContactStore contactStore, ChatConversation item)
        {
            try
            {
                var contact = await contactStore.GetContactAsync(item.ThreadingInfo.ContactId);

                var photo = await contact.LargeDisplayPicture.OpenReadAsync();

                var img = new BitmapImage();
                await img.SetSourceAsync(photo);

                return(img);
            }
            catch
            {
                return(null);
                //var img = new BitmapImage(new Uri("ms-appx:///Assets/StoreLogo.png"));
                //return img;
            }
        }
コード例 #10
0
        public async Task <Contact> PromptUserForContactAsync()
        {
            // Open the prompt
            var contactPicker = new ContactPicker()
            {
                SelectionMode = ContactSelectionMode.Contacts
            };

            Contact contact = await contactPicker.PickContactAsync();

            if (contact != null)
            {
                // Fetch all the details
                ContactStore contactStore = await PromptForPermissionsAsync();

                contact = await contactStore.GetContactAsync(contact.Id);
            }

            return(contact);
        }
コード例 #11
0
        /// <summary>
        /// Get DiscordId from ContactId
        /// </summary>
        /// <param name="id">ContactId</param>
        /// <returns>DiscordId</returns>
        public async Task <string> ContactIdToRemoteId(string id)
        {
            if (store == null)
            {
                //Unavailable, call it quits
                return(string.Empty);
            }

            // Get contact annotations
            var fullContact = await store.GetContactAsync(id);

            var contactAnnotations = await(await Windows.ApplicationModel.Contacts.ContactManager.RequestAnnotationStoreAsync(ContactAnnotationStoreAccessType.AppAnnotationsReadWrite)).FindAnnotationsForContactAsync(fullContact);

            // If contact contains annotations
            if (contactAnnotations.Count >= 0)
            {
                // Return RemoteId
                return(contactAnnotations[0].RemoteId);
            }

            return(string.Empty);
        }
コード例 #12
0
        internal async void PickButton_Click(object sender, RoutedEventArgs e)
        {
            if (UIEnabled)
            {
                UIEnabled = false;
                ContactPicker contactPicker = new ContactPicker();
                contactPicker.SelectionMode = ContactSelectionMode.Fields;
                contactPicker.DesiredFieldsWithContactFieldType.Add(ContactFieldType.PhoneNumber);
                var contact = await contactPicker.PickContactAsync();

                if (contact != null)
                {
                    // The contact we just got doesn't contain the contact picture so we need to fetch it
                    // see https://stackoverflow.com/questions/33401625/cant-get-contact-profile-images-in-uwp
                    ContactStore contactStore = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AllContactsReadOnly);

                    // If we do not have access to contacts the ContactStore will be null, we can still use the contact the user
                    // seleceted however
                    if (contactStore != null)
                    {
                        Contact realContact = await contactStore.GetContactAsync(contact.Id);

                        if (realContact.SourceDisplayPicture != null)
                        {
                            using (var stream = await realContact.SourceDisplayPicture.OpenReadAsync())
                            {
                                BitmapImage bitmapImage = new BitmapImage();
                                await bitmapImage.SetSourceAsync(stream);

                                ContactPhoto = bitmapImage;
                            }
                        }
                        else
                        {
                            ContactPhoto = null;
                        }
                    }
                    ContactName = contact.Name;
                    if (contact.Phones.Count > 0)
                    {
                        var originalNumber = contact.Phones[0].Number;
                        if (originalNumber[0] != '+')
                        {
                            // need a better way of determining the "default" country code here
                            var formattedPhoneNumber = PhoneNumberFormatter.FormatE164("1", originalNumber);
                            if (string.IsNullOrEmpty(formattedPhoneNumber))
                            {
                                ContactNumber = originalNumber;
                                MessageDialog message = new MessageDialog("Please format the number in E.164 format.", "Could not format number");
                                await message.ShowAsync();
                            }
                            else
                            {
                                ContactNumber = formattedPhoneNumber;
                            }
                        }
                    }
                }
                UIEnabled = true;
            }
        }
コード例 #13
0
        async private void selectContact_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                ContactPicker contactPicker = new ContactPicker();
                contactPicker.CommitButtonText = "Select";
                contactPicker.SelectionMode    = ContactSelectionMode.Contacts;
                Contact tmp = await contactPicker.PickContactAsync();

                if (tmp == null)
                {
                    status.Log(LocalizableStrings.CONTACTS_NO_CONTACT_SELECTED);
                    return;
                }
                status.Log(LocalizableStrings.CONTACTS_CONTACT_SELECTED);

                ContactStore store = await ContactManager.RequestStoreAsync();

                // BUG on Desktop tmp.Id is an empty string.
                Debug.WriteLine(tmp.Id);
                if (string.IsNullOrEmpty(tmp.Id))
                {
                    status.Log(LocalizableStrings.CONTACTS_NO_CONTACT_DETAILS);
                    return;
                }

                Contact contact = await store.GetContactAsync(tmp.Id);

                if (contact == null)
                {
                    status.Log(LocalizableStrings.CONTACTS_NO_CONTACT_DETAILS);
                    return;
                }
                status.Log(LocalizableStrings.CONTACTS_CONTACT_DETAILS_FOUND);

                BitmapImage bitmap = null;
                if (contact.Thumbnail != null)
                {
                    IRandomAccessStreamWithContentType stream = await contact.Thumbnail.OpenReadAsync();

                    if (stream != null && stream.Size > 0)
                    {
                        bitmap = new BitmapImage();
                        bitmap.SetSource(stream);
                    }
                }
                thumbnail.Source = bitmap;

                string name = contact.DisplayName;
                if (!string.IsNullOrEmpty(name))
                {
                    contactName.Text = name;
                }

                ContactEmail email = contact.Emails.FirstOrDefault();
                if (email != null)
                {
                    contactEmail.Text = email.Address;
                }

                ContactPhone phone = contact.Phones.FirstOrDefault();
                if (phone != null)
                {
                    contactPhone.Text = phone.Number;
                }

                ContactAddress address = contact.Addresses.FirstOrDefault();
                if (address != null)
                {
                    contactAddress.Text = address.StreetAddress;
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());
                status.Log(ex.Message);
            }
        }