0

The following code returns Phone number as null for the contacts in SIM. Whereas for the contacts in Phone, it returns the correct value. Please let me know, whether the URI should be different to read the phone number from SIM. Below is my code, almost a copy from Android Contact tutorial.

                            long contactId = -1;

            // Load the display name for the specified person
            Cursor cursor = contentResolver.query(contactUri,new String[]{Contacts._ID, Contacts.DISPLAY_NAME}, null, null, null);
            try 
            {
                if (cursor.moveToFirst()) 
                {
                    contactId = cursor.getLong(0);
                }
            }
            finally
            {
                cursor.close();
            }

            // Load the phone number (if any).
            String phoneNumber=null;
            cursor = contentResolver.query(Phone.CONTENT_URI,new String[]{Phone.NUMBER},Phone.CONTACT_ID + "=" + contactId, null, Phone.IS_SUPER_PRIMARY + " DESC");
            try 
            {
                if (cursor.moveToFirst()) 
                {
                    phoneNumber=cursor.getString(0);

                }
            } 
            finally 
            {
                cursor.close();
            }
Sam
  • 555
  • 4
  • 13
  • Check this: http://stackoverflow.com/questions/2356084/read-all-contacts-phone-numbers-in-android – Caner Sep 26 '11 at 15:41
  • @LAS_VEGAS But that link procedure uses deprecated API !! – Sam Sep 26 '11 at 15:50
  • How about this: http://stackoverflow.com/questions/3208061/android-how-to-access-the-sim-contact-table-using-the-sdk – Caner Sep 26 '11 at 15:54

0 Answers0