Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - Show list of contacts with same phone number

I have a widget that will open the contacts list by a phone number. I am using Contacts.Intents.SHOW_OR_CREATE_CONTACT I know it's deprecated but I want this to work on android 1.6. I have a phone number to use on the lookup intent. here is the code

Intent contViewIntent = new Intent(Contacts.Intents.SHOW_OR_CREATE_CONTACT);
contViewIntent.setData(Uri.fromParts("tel", number, null));

PendingIntent contPendIntent = PendingIntent.getActivity(context, 0, contViewIntent, 0);
views.setOnClickPendingIntent(viewID, contPendIntent);

When the Contact list has 2 or more contacts with the same number then this will open the list of contacts and has the user select one. This works fine on 1.6, but on 2.0 and above it shows a list of contacts with just the number 1 or number 2 in the names and when you select one of those from the list to view you get an error.

04-09 19:12:47.891: ERROR/CursorWindow(105): Bad request for field slot 0,6. numRows = 2, numColumns = 6

04-09 19:12:47.992: ERROR/AndroidRuntime(105): java.lang.IllegalStateException: get field slot from row 0 col 6 failed

how do I get this to work on 1.6 and 2.0 above?

like image 512
Jarad Duersch Avatar asked Nov 14 '22 11:11

Jarad Duersch


1 Answers

Android 2.0 has a completely new API for managing contacts (look up ContactsContract). In my app, I ended up writing the low-level contact management twice - once for 2.0, once for 1.6 and under (I check via reflection to see if the ContactsContract class exists and switch to the 2.0+ code in that case).

like image 179
EboMike Avatar answered Dec 17 '22 09:12

EboMike