Thursday, 29 March 2012

Work with contacts

http://app-solut.com/blog/2011/03/working-with-the-contactscontract-to-query-contacts-in-android/
http://chengalva.com/dnn_site/Articles/tabid/41/EntryId/87/Android-What-is-managedQuery-in-Android.aspx
get number in Contacts
   Uri uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;
        String[] projection    = new String[] {ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,
                        ContactsContract.CommonDataKinds.Phone.NUMBER};

       
        Cursor people = getContentResolver().query(uri, projection, null, null, null);

        int indexName = people.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME);
        int indexNumber = people.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);

        people.moveToFirst();
        String name;
        String number;
        myTextView = (TextView) findViewById(R.id.myTextView);
        do {
             name = people.getString(indexName);
            number = people.getString(indexNumber);
      //      myTextView.setText(myTextView.getText().toString() + " **** " + number);
           
           
        } while (people.moveToNext());

No comments:

Post a Comment