Take a look at this sample app that makes use of both old and new APIs:

http://code.google.com/p/android-business-card/source/browse/#svn/trunk/android-business-card/BusinessCard/src/com/example/android/businesscard

In the redesign of the Contacts API we had several goals: add support
for multiple types of accounts, add support for multiple accounts, add
support for account-specific data types, etc.  These goals were
incompatible with the overall structure of the old APIs, so we had to
redisign them from scratch.  This was a major step, sort-of like going
from English measurement units to metric system or going from a manual
transmission car to automatic.  This type of change is supposed to be
a rare event, painful for everyone, but ultimately the platform to a
whole new level.

Cheers,
- Dmitri


On Mon, Dec 7, 2009 at 8:12 AM, agirardello <[email protected]> wrote:
> Sorry for being away...
>
> I managed to get it to work, however I complain with the approach used
> in developing the API! Apparently, searching for a contact based on
> the phone number has changed in Android 2.0 and the "old good way" of
> doing that isn't working anymore (Why????????). I agree that now it is
> much more intuitive, however it is a mess for the compatibility
> (unless I was doing it wrong in API level 3 and 4, any lines of code
> to share?).
>
> Here the code for API level >= 5:
>
> Uri lookupUri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI,
> Uri.encode(number));
> Cursor c = context.getContentResolver().query(lookupUri, null, null,
> null, null);
> if (c.getCount() > 0) {
>   c.moveToFirst();
>   return c.getString(c.getColumnIndex( PhoneLookup.DISPLAY_NAME ));
> } else {
>   // Not found, do something else...
> }
>
> In any case, to be compatible with API level <= 4 PhoneLookup cannot
> be referenced in the code (as well as other things) and must be loaded
> through reflection. Am I wrong? Other solution?
>
> Looking forward to hear something from a more experienced Android
> developer...
>
> Best,
>
> Andrea ;-)
>
>
>
>
> On Dec 5, 5:36 pm, ghassett <[email protected]> wrote:
>> Yes Dmitri, this is exactly what I am doing -- I am not manually
>> inserting records into thecontactsdb like the test case does, but
>> there is definitely a contact with a mobile phone number
>> "617939xxxx" (with real digits, not "x"s), and when I open a cursor on
>> the query:
>>
>> Uri filterUri1 = Uri.withAppendedPath(Phones.CONTENT_FILTER_URL,
>> "617939xxxx"); // with real digits, not "x"s
>>
>> I get back a valid cursor, but no rows (moveToFirst() returns false)
>> -- on 2.0 emulator only.  On 1.6 emulator, it works fine.
>>
>> // greg //
>>
>> On Dec 4, 7:21 pm, Dmitri Plotnikov <[email protected]> wrote:
>>
>> > 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/Contacts...
>>
>> > 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 thatContactsportion 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 accessingcontacts'
>> > >> > > > 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 readingcontactsby 
>> > >> > > > 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 samplecontactsin 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
>

-- 
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

Reply via email to