Thursday 8 August 2013

Get Contact name,number and photo

 public  void getNameContactDetails(){
        ContentResolver cr = getContentResolver();
        ContactSetGet contactsetgte;
        ArrayList<ContactSetGet> names = new ArrayList<ContactSetGet>();
        Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI,
               null, null, null,null);
       
        if (cur.getCount() > 0) {
           while (cur.moveToNext()) {
               String cont_id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID));
              String cont_name = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
               String photoId = cur.getString(cur.getColumnIndex(Contacts.PHOTO_ID));
                String phototjumb = cur.getString(cur.getColumnIndex(Contacts.PHOTO_THUMBNAIL_URI));
               if (Integer.parseInt(cur.getString(cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {
                   System.out.println("name : " + cont_name + ", ID : " + cont_id);
                   System.out.println("photoId : " + photoId);
                   System.out.println("phototjumb : " + phototjumb);

                   // get the phone number
                   Cursor pCur = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,null,
                                          ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = ?",
                                          new String[]{cont_id}, null);
                   while (pCur.moveToNext()) {
                    String cont_phone = pCur.getString(
                                pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
                         System.out.println("phone" + cont_phone);
                   }
                 pCur.close();
                }
           }
        }
    }


declair this method in your oncreate method


No comments:

Post a Comment

Comments

Find Hours Diffrence in Kotlin

  In Kotlin, determining the difference in hours between two timestamps is a common task, especially in scenarios involving time-based calcu...