Hi Greg, Take a look at the testPhonesFilterQuery unit test we have for verifying the behavior in question:
http://android.git.kernel.org/?p=platform/packages/providers/ContactsProvider.git;a=blob;f=tests/src/com/android/providers/contacts/LegacyContactsProviderTest.java;hb=HEAD Is what it's doing correct? Is it different from what you are doing? Thank you, - Dmitri On Fri, Dec 4, 2009 at 4:00 PM, ghassett <[email protected]> wrote: > Hi Dmitri -- I am not sure that the old API is still functional. I am > using what I think is the standard way of getting a display name from > a phone number -- see the code below -- and it functions on a 1.6 > emulator but on on a 2.0 emulator. Am I doing something wrong? Is > there an example somewhere of how to "get a contact name from a phone > number" that will function in 1.5, 1.6, and 2.0? > > Here's the code -- it works when run in the 1.6 emulator, but not in > the 2.0 emulator (Cursor comes back non-null, but there are no records > so moveToFirst returns false): > > public String getDisplayName (ContentResolver contentResolver) > { > String retval = mPhoneNumber; > > Cursor cursor = contentResolver.query( > Uri.withAppendedPath > (Contacts.Phones.CONTENT_FILTER_URL, > Uri.encode(mPhoneNumber)), > new String[] { Contacts.Phones.DISPLAY_NAME }, > null, null, null); > > if (cursor != null && cursor.moveToFirst()) > { > retval = cursor.getString(0); > } > > return retval; > } > > > // thanks // greg // > > > > On Oct 30, 3:05 pm, Dmitri Plotnikov <[email protected]> wrote: >> It's deprecated, not removed. The old API is still functional, but with >> restrictions: >> >> 1. If your app was using something non-public, that part is likely to break. >> We tested a bunch of apps on the market against the legacy API - most >> worked, but some did not. Those were the cases when the app was using some >> knowledge of the undocumented underlying database structure. >> 2. Legacy API will only give you access to the "primary" account, i.e. the >> first Google account you add to the phone. >> >> - Dmitri >> >> On Fri, Oct 30, 2009 at 11:40 AM, nEx.Software <[email protected] >> >> > wrote: >> >> > Hold up... I'm confused. Are you saying that Contacts portion of the >> > SDK is deprecated? Whatever happened to "stick to the SDK because >> > those are stable apis that won't break in future versions"? Very >> > disappointing... >> >> > On Oct 30, 11:12 am, Jeff Sharkey <[email protected]> wrote: >> > > Could you post the exact Uri you're passing to query()? As the >> > > javadoc describes, you need to append a filter string to the >> > > CONTENT_FILTER_URI so it knows what to filter on. >> >> > > Uri lookupUri = Uri.withAppendedPath(PhoneLookup.CONTENT_URI, >> > phoneNumber); >> >> > > Also, you might be able to skip your second step, since you can >> > > directly ask for the PhoneLookup.DISPLAY_NAME column in the >> > > projection. >> >> > > j >> >> > > On Fri, Oct 30, 2009 at 8:05 AM, agirardello >> >> > > <[email protected]> wrote: >> >> > > > Dear all, >> >> > > > I'm trying to adapt my application (Personalytics) for the brand new >> > > > Android 2.0, however I'm facing an issue while accessing contacts' >> > > > phone numbers... >> >> > > > What I need to do is to retrieve the name associated to a stored >> > > > contact based on his/her phone number. At present I'm doing this in >> > > > two steps: >> > > > 1) from a phone number I get the corresponding ID of the stored >> > > > contact (if present) >> > > > 2) I retrieve the contact's name based on that ID >> >> > > > I managed to use the correct CONTENT_URI for reading contacts by using >> > > > reflection to be fully compatible with Android 2.0 >> > > > (ContactsContract.Contacts.CONTENT_URI) and the previous versions >> > > > (People.CONTENT_URI). >> >> > > > Now I'm trying to do the same for Phones.CONTENT_URI (Android <= 1.6) >> > > > and ContactsContract.PhoneLookup.CONTENT_FILTER_URI (Android = 2.0) >> > > > which is needed by step 2) mentioned above. But as soon as I try to >> > > > get a contentResolver by using >> > > > ContactsContract.PhoneLookup.CONTENT_FILTER_URI I get the following >> > > > exception: >> >> > > > java.lang.IllegalArgumentException: Unknown URL >> > content://com.android.contacts/phone_lookup >> >> > > > This looks really strange to me, since it should be correct (it is >> > > > part of the official API)! Moreover, I tried to look at the "API >> > > > Demos" project, in particular to the classes: >> >> > > > com.example.android.apis.view.List2 >> > > > com.example.android.apis.view.List3 >> >> > > > which are still using the deprecated People.CONTENT_URI and >> > > > Phones.CONTENT_URI and thus no data (i.e. contacts) is loaded (of >> > > > course I have sample contacts in the emulator). >> >> > > > - Do you have any suggestion to solve this problem? >> > > > - Or is there another approach I can use to get the name of a contact >> > > > based on one of his/her numbers? (This must work on all versions of >> > > > Android) >> >> > > > Thank you!!!!!!!! ;-) >> >> > > > Andrea >> >> > > -- >> > > Jeff Sharkey >> > > [email protected] >> > --~--~---------~--~----~------------~-------~--~----~ >> > You received this message because you are subscribed to the Google >> > Groups "Android Developers" group. >> > To post to this group, send email to [email protected] >> > To unsubscribe from this group, send email to >> > [email protected]<android-developers%[email protected]> >> > For more options, visit this group at >> >http://groups.google.com/group/android-developers?hl=en >> > -~----------~----~----~----~------~----~------~--~--- > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en > -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

