Android Phone Number Using Loader Invalid Column Data1

I used to use a content resolver to get a list of contacts and their data while it still works. I wanted to try the Loader method, which requests the content provider in the background. I looked at the documentation and sample code here:

http://developer.android.com/training/contacts-provider/retrieve-details.html

While I was able to display the contact list without any problems, I was stuck in getting the phone number of a specific contact when I click on it and show it on the detailed screen. The demo above shows the user address on the details screen, I even tried to change it. I changed the content URI from contacts in ContactsContract.CommonDataKinds.Phone, but I keep getting

java.lang.IllegalArgumentException: Invalid column data1 

There is not a single detailed tutorial on the Internet showing how to do this. Can someone here be kind enough to shed light? While reading various other questions related to Stackoverflow, I am sure that it has something to do with 2 different URI CONTENTs, but again I am wrong. Any help or pointers would be really appreciated. Thanks

A few of the SO questions I have already looked at are:

Get phone number from contact bootloader in android: projection crash

Logcat says "invalid column1 data"

How to get a phone number for contacts in Android

Getting a phone number from a search URI

None of them solves my problem. Here is the relevant code where it fails:

  final static String[] PROJECTION = { Contacts._ID, Utils.hasHoneycomb() ? ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME_PRIMARY : ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME //ContactsContract.CommonDataKinds.Phone.NUMBER, }; 

The code works very well, but the moment I delete the comment to get the phone number, it fails

+2
android contacts
Feb 16 '14 at 13:30
source share
2 answers

This is an excerpt from what I actually do in my (working) code.

This is my corresponding import:

 import android.provider.ContactsContract; import android.provider.ContactsContract.CommonDataKinds.Email; import android.provider.ContactsContract.CommonDataKinds.Phone; import android.provider.ContactsContract.Contacts; 

Given that id is a string (representing a number, such as "1", "20", ...)

 // Query for phone numbers for the selected contact id final Cursor cur = getContentResolver().query ( Phone.CONTENT_URI, null, Phone.CONTACT_ID + "=?", new String[] {id}, null ); final int phoneIdx = cur.getColumnIndex(Phone.NUMBER); final int phoneType = cur.getColumnIndex(Phone.TYPE); // ... if(cur.moveToFirst()) { final String name = cur.getString ( cur.getColumnIndexOrThrow ( ContactsContract.Contacts.DISPLAY_NAME ) ); } 

We hope that he will put you on the right path.

0
Feb 16 '14 at
source share

In my case, the problem was the URI .

I used this:

 Uri uri = ContactsContract.Contacts.CONTENT_URI; 

and I changed for this ( Phone.CONTENT_URI ) to solve the problem and get the phone number:

 Uri uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI; 

This is the rest of the code:

 contactos = (TextView) findViewById(R.id.contactos); Uri uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI; String [] projection = new String[] { ContactsContract.Contacts._ID, ContactsContract.Contacts.DISPLAY_NAME, ContactsContract.CommonDataKinds.Phone.NUMBER }; Cursor cursor = getContentResolver().query(uri, projection, null, null, null); while (cursor.moveToNext()){ String nombre = cursor.getString(cursor.getColumnIndex(ContactsContract.Data.DISPLAY_NAME)); String telefono = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)); contactos.append("Name: "); contactos.append(nombre); contactos.append(" - Phone Number: "); contactos.append(telefono); contactos.append("\n"); } 
+4
Aug 01 '15 at 4:04 on
source share



All Articles