I've come up with a work around for use on the HTC HERO, for getting
the URI for a newly created contact after the ACTION_INSERT intent
returns.

Basically I just do a query on the Contacts.People table and return a
URI with the newest id if the intent result returns RESULT_OK.

code:
//----------------
protected void onActivityResult(int requestCode, int resultCode,
Intent data) {
        if (requestCode == CREATE_CONTACT_REQUEST) {
                if (resultCode == RESULT_OK) {
                        Uri newUri = null;
                        if (data != null) {
                                newUri = data.getData();
                        } else {
                                // a new contact was created but the Contacts 
app
                                // implementation didn't return us a uri
                                // This happens on HTC_HERO and maybe some 
other devices.
                                // As a work around let's set the newUri to the 
uri of the
                                // most recently added contact
                                // returned from a query of the contacts. 
(returns uri with
                                // most recent contact _ID)
                                newUri = getNewestContactUri();
                        }
                        if (newUri != null) {
                                // do something with the new Uri
                        }
                }
        }
}

public Uri getNewestContactUri() {
        String[] projection = new String[] { Contacts.People._ID };
        String orderBy = Contacts.People._ID + " DESC";
        Cursor cursor = curContext().getContentResolver().query(
                        Contacts.People.CONTENT_URI, projection, null, null, 
orderBy);
        int idIdx = -1;
        try {
                idIdx = cursor.getColumnIndexOrThrow(Contacts.People._ID);
        } catch (Exception e) {
                e.printStackTrace();
                idIdx = -1;
        }
        if (idIdx != -1) {
                int id = -1;
                if (cursor.moveToFirst()) {
                        id = cursor.getInt(idIdx);
                }
                if (id != -1) {
                        return Uri.withAppendedPath(Contacts.People.CONTENT_URI,
                                        Integer.toString(id));
                }
        }
        return null;
}


On Nov 13, 3:10 pm, Mark Murphy <[email protected]> wrote:
> jak. wrote:
> > On every other device when: resultCode == RESULT_OK  it's safe to
> > assume that data contains the uri for the newly created contact.
> > However on the Hero they return RESULT_OK, yet data is equal to null!
>
> That feels like a bug.
>
> > Also is anyone aware of a place to report bugs to HTC?
> > I searched around on their developer sitehttp://developer.htc.com/
> > but didn't find anything.
>
> There's an email address ([email protected]) on that site's Tattoo
> support page. It's worth a shot.
>
> I have also been working some back channels to try to get some attention
> paid to the Hero app icon issue that's been discussed a lot recently,
> and that may have some trickle-down effects to get other Hero-specific
> issues investigated.
>
> --
> Mark Murphy (a Commons 
> Guy)http://commonsware.com|http://twitter.com/commonsguy
>
> Warescription: Three Android Books, Plus Updates, $35/Year

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