How to retrieve Contact name and phone number in Android

后端 未结 6 1259
旧时难觅i
旧时难觅i 2020-12-10 05:56

I\'m trying to retrieve contact list with there name and phone numbers. I try following code:

 // Get a cursor over every contact.
    Cursor cursor = getCon         


        
6条回答
  •  时光取名叫无心
    2020-12-10 06:40

    Don't use deprecated API access like as follow

            Cursor cursor = getContentResolver().
        query( Contacts.CONTENT_URI, 
                new String[]{Contacts.DISPLAY_NAME}, null, null,null);
        if(cursor!=null){
            while(cursor.moveToNext()){
                Cursor c = getContentResolver().query(Phone.CONTENT_URI, new String[]{Phone.NUMBER, Phone.TYPE}, 
                        " DISPLAY_NAME = '"+cursor.getString(cursor.getColumnIndex(Contacts.DISPLAY_NAME))+"'", null, null);
                while(c.moveToNext()){
                    switch(c.getInt(c.getColumnIndex(Phone.TYPE))){
                    case Phone.TYPE_MOBILE :
                    case Phone.TYPE_HOME :
                    case Phone.TYPE_WORK :
                    case Phone.TYPE_OTHER :
                    }
                }
            }
        }
    

提交回复
热议问题