如何从android中选择独特的联系人

如何从android中选择独特的联系人,第1张

概述我想从 Android只选择具有电话号码的联系人的唯一联系人.我正在使用此代码 ContentResolver cr = getContentResolver(); Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, ContactsContra 我想从 Android只选择具有电话号码的联系人的唯一联系人.我正在使用此代码
ContentResolver cr = getContentResolver();        Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI,null,ContactsContract.Contacts.disPLAY_name);        // Find the ListVIEw resource.        mainListVIEw = (ListVIEw) findVIEwByID(R.ID.mainListVIEw);        // When item is tapped,toggle checked propertIEs of CheckBox and        // Planet.        mainListVIEw                .setonItemClickListener(new AdapterVIEw.OnItemClickListener()                {                    public voID onItemClick(AdapterVIEw<?> parent,VIEw item,int position,long ID)                    {                        ContactsList planet = listadapter.getItem(position);                        planet.toggleChecked();                        PlanetVIEwHolder vIEwHolder = (PlanetVIEwHolder) item                                .getTag();                        vIEwHolder.getCheckBox().setChecked(planet.isChecked());                    }                });        // Create and populate planets.        planets = (ContactsList[]) getLastNonConfigurationInstance();        // planets = new Planet[10];        // planets.Add("asdf");        ArrayList<ContactsList> planetList = new ArrayList<ContactsList>();        String phoneNumber = null;        String phoneType = null;        count = cur.getCount();        contacts = new ContactsList[count];        if (planets == null)        {            if (cur.getCount() > 0)            {                planets = new ContactsList[cur.getCount()];                int i = 0;                //                while (cur.movetoNext())                {                    String ID = cur.getString(cur                            .getColumnIndex(ContactsContract.Contacts._ID));                    String name = cur                            .getString(cur                                    .getColumnIndex(ContactsContract.Contacts.disPLAY_name));                    if (Integer                            .parseInt(cur.getString(cur                                    .getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0)                    {                        // query phone here. Covered next                        Cursor pCur = cr                                .query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,ContactsContract.CommonDataKinds.Phone.CONTACT_ID                                                + " = ?",new String[]                                        { ID },null);                        // WHILE WE HAVE CURSOR GET THE PHONE NUMERS                        while (pCur.movetoNext())                        {                            // Do something with phones                            phoneNumber = pCur                                    .getString(pCur                                            .getColumnIndex(ContactsContract.CommonDataKinds.Phone.DATA));                            phoneType = pCur                                    .getString(pCur                                            .getColumnIndex(ContactsContract.CommonDataKinds.Phone.TYPE));                            Log.i("Pratik",name + "'s PHONE :" + phoneNumber);                            Log.i("Pratik","PHONE TYPE :" + phoneType);                        }                        pCur.close();                    }                    planets = new ContactsList[]                    { new ContactsList(name,phoneNumber) };                    contacts[i] = planets[0];                    planetList.addAll(Arrays.asList(planets));                    i++;                }            }

此代码检索所有联系人并将其放入列表中.但我想要独特的联系,只有那些没有电话的人.我怎样才能做到这一点??有什么方法可以在查询中传递一些参数来只选择唯一的联系人???

解决方法 我想你的意思是你有一些联系人的重复记录.因此,您必须为查询添加条件.关键部分是联系人必须在可见组中并且有电话号码.
String selection = ContactsContract.Contacts.IN_VISIBLE_GROUP + " = '"                + ("1") + "'";        String sortOrder = ContactsContract.Contacts.disPLAY_name                + " ColLATE LOCAliZED ASC";cur = context.getContentResolver().query(                ContactsContract.Contacts.CONTENT_URI,projection,selection                        + " AND " + ContactsContract.Contacts.HAS_PHONE_NUMBER                        + "=1",sortOrder);// this query only return contacts which had phone number and not duplicated
总结

以上是内存溢出为你收集整理的如何从android中选择独特的联系人全部内容,希望文章能够帮你解决如何从android中选择独特的联系人所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1130874.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-30
下一篇2022-05-30

发表评论

登录后才能评论

评论列表(0条)

    保存