Exemplo n.º 1
0
        private void MultiPass()
        {
            try
            {
                string[] userIds = new string[] { "792",
                                                  "757",
                                                  "770",
                                                  "771",
                                                  "843",
                                                  "961",
                                                  "960",
                                                  "988",
                                                  "752", };
                string selection = GetSelection(userIds);

                string[] parameters = userIds.Concat(new string[] { "0" }).ToArray();

                var cr = ContentResolver;
                using (var pCur = cr.Query(Phone.ContentUri, null, selection, parameters, null))
                {
                    var x       = pCur.GetColumnNames();
                    var reader2 = new CursorReader <YarlyContact>(pCur, c =>
                    {
                        int numberField = c.GetColumnIndex(Phone.Number);
                        string phoneNo  = c.GetString(numberField);

                        return(new YarlyContact(null, phoneNo));
                    });

                    foreach (var item in reader2)
                    {
                        try
                        {
                            Console.WriteLine(item);
                        }
                        catch (Exception)
                        {
                            throw;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            return;
        }
Exemplo n.º 2
0
        private IEnumerable <YarlyContact> GetPhoneNumbersSlow()
        {
            List <string> numbers = new List <string>();
            Dictionary <string, string> userIds = new Dictionary <string, string>();
            var cr = ContentResolver;

            using (var cur = cr.Query(ContactsContract.Contacts.ContentUri, null, null, null, null))
            {
                var reader = new CursorReader <CursorContact>(cur, c => new CursorContact(c));

                foreach (var contact in reader.Where(c => c.HasPhone))
                {
                    string   selection  = Phone.InterfaceConsts.ContactId + " = ?";
                    string[] parameters = new string[] { contact.Id };
                    userIds[contact.Id] = contact.Id;

                    using (var pCur = cr.Query(Phone.ContentUri, new string[] { Phone.Number }, selection, parameters, null))
                    {
                        var x       = pCur.GetColumnNames();
                        var reader2 = new CursorReader <YarlyContact>(pCur, c =>
                        {
                            int numberField = c.GetColumnIndex(Phone.Number);
                            string phoneNo  = pCur.GetString(numberField);
                            return(new YarlyContact(contact.DisplayName, phoneNo));
                        });

                        foreach (var item in reader2)
                        {
                            yield return(item);
                        }
                        break;
                    }
                }
            }

            //DumpIds(userIds);
        }
Exemplo n.º 3
0
        private IEnumerable <YarlyContact> GetPhoneNumbers()
        {
            List <string> userIds = null;
            var           cr      = ContentResolver;

            string idColumnName = ContactsContract.PhoneLookup.InterfaceConsts.Id;

            using (var cur = cr.Query(ContactsContract.Contacts.ContentUri, new string[] { idColumnName }, null, null, null))
            {
                int idIndex = cur.GetColumnIndex(idColumnName);

                var reader = new CursorReader <string>(cur, c => c.GetString(idIndex));
                userIds = reader.ToList();
            }

            string selection = GetSelection(userIds);

            userIds.Add("0"); // has phone

            using (var pCur = cr.Query(Phone.ContentUri,
                                       null, //new string[] { ContactsContract.PhoneLookup.InterfaceConsts.DisplayName, Phone.Number },
                                       selection,
                                       userIds.ToArray(),
                                       null))
            {
                var x                = pCur.GetColumnNames();
                int numberField      = pCur.GetColumnIndex(Phone.Number);
                int displayNameField = pCur.GetColumnIndex(ContactsContract.PhoneLookup.InterfaceConsts.DisplayName);

                var reader2 = new CursorReader <YarlyContact>(pCur, c =>
                {
                    for (int i = 0; i < pCur.GetColumnNames().Count(); i++)
                    {
                        {
                            try
                            {
                                string name  = pCur.GetColumnName(i);
                                string value = pCur.GetString(i);
                                Console.WriteLine("{0} - {1}", name, value);
                            }
                            catch (Exception)
                            {
                            }
                        }
                    }

                    Console.WriteLine();
                    Console.WriteLine();
                    Console.WriteLine();
                    Console.WriteLine();

                    string phoneNo     = pCur.GetString(numberField);
                    string displayName = pCur.GetString(displayNameField);

                    return(new YarlyContact(displayName, phoneNo));
                });

                foreach (var item in reader2)
                {
                    Console.WriteLine(item);
                    yield return(item);
                }
            }
        }