Got it, thanks.  I just did Uri.parse() on that a string containing
"content://...".

It would certainly be nice if we didn't have to manually type that
entire URI address in... some way we could access the ENTIRE Uri for
People, Phones, etc.  Even referencing People.CONTENT_URI.getPath()
fails to show the "content://contacts" portion of the Uri.

On Aug 27, 4:42 pm, "Megha Joshi" <[EMAIL PROTECTED]> wrote:
> Yes it would crash, because then the Uri value you get does not include the
> base contacts uri...which is content://contacts.
>
> The uri value should be something like:
> content://contacts/people/<person_id>
> As long as the Uri value is in this format and the person_id is present in
> the content provider it should work...
> You can use ContentUris.withAppendedId(People.CONTENT_URI, <person_id>) to
> generate the correct Uri ..
>
> 2008/8/27 kingkung <[EMAIL PROTECTED]>
>
>
>
> > If you try that code in your demo (and print out the Uri for
> > debugging), it will crash with a null pointer exception.
>
> > I also tried using Uri.Builder to rebuild the contact Uri, and that
> > didn't work either.
>
> > On Aug 27, 4:31 pm, kingkung <[EMAIL PROTECTED]> wrote:
> > > /people/189 is the uri i get.
>
> > > On Aug 27, 4:24 pm, "Megha Joshi" <[EMAIL PROTECTED]> wrote:
>
> > > > You definitely don't need to store the URI, what are the first and
> > second
> > > > URI values that you get?
>
> > > > 2008/8/27 kingkung <[EMAIL PROTECTED]>
>
> > > > > I added one simple line to the demo and it crashed with a null
> > pointer
> > > > > exception.  Apparently I can't recreate a second Uri from an original
> > > > > Uri.
>
> > > > >  private void readContact(Uri uri) {
> > > > >    ImageView i = (ImageView) findViewById(R.id.image);
> > > > >    Uri uri2 = Uri.parse(uri.getEncodedPath());
> > > > >    Bitmap b = People.loadContactPhoto(this, uri2, 0, null);
> > > > >    i.setImageBitmap(b);
> > > > >  }
>
> > > > > This is a terrible scenario, because people don't necessarily store
> > > > > and retrieve within the same operations, and I have no idea how to
> > > > > store a Uri except storing its path as a String.
>
> > > > > How do I get around this??
>
> > > > > On Aug 27, 3:04 pm, "Megha Joshi" <[EMAIL PROTECTED]> wrote:
> > > > > > Please refer to the attached sample code for setting a contact's
> > image
> > > > > and
> > > > > > loading it..
> > > > > > I didn't get null pointer exception so perhaps there is something
> > else
> > > > > going
> > > > > > on with your code...
>
> > > > > > 2008/8/27 kingkung <[EMAIL PROTECTED]>
>
> > > > > > > I'm having trouble getting the new contact photo methods for 0.9
> > beta
> > > > > > > to work correctly.
>
> > > > > > > This is what I do currently:
>
> > > > > > >        private static boolean storePhoto(Context context,
> > > > > AndroidContact
> > > > > > > ac,Uri personUri)
> > > > > > >        {
> > > > > > >                byte[] bytes =
> > > > > > > ExternalServices.retrieveBytesFromURL(ac.photoUrl);
> > > > > > >                People.setPhotoData(context.getContentResolver(),
> > > > > personUri,
> > > > > > > bytes);
> > > > > > >                return true;
> > > > > > >        }
>
> > > > > > > where the path of the personUri is something like "/people/57"
>
> > > > > > > To retrieve, I use the same personUri, and do:
>
> > > > > > >      public void loadPhoto(Uri personUri) throws Exception
> > > > > > >      {
> > > > > > >                Bitmap b = null;
> > > > > > >                b=People.loadContactPhoto(f_context, personUri,
> > > > > > > R.drawable.no_photo_found,null);
> > > > > > >                if (b!=null)
> > > > > > >                        photoView.setImageBitmap(b);
> > > > > > >                else
>
> > > > > > >  photoView.setImageResource(R.drawable.no_photo_found);
> > > > > > >     }
>
> > > > > > > Store seems to work correctly as far as I can tell, but retrieve
> > > > > > > throws a NullPointerException on the line
>
> > > > > > > b=People.loadContactPhoto(f_context, personUri,
> > > > > > > R.drawable.no_photo_found,null);
>
> > > > > > > which is amazing, because none of the parameters (outside of the
> > last
> > > > > > > one) are null.
>
> > > > > > > What is going on?
>
> > > > > >  ContactsDemo.zip
> > > > > > 51KViewDownload
>
>
--~--~---------~--~----~------------~-------~--~----~
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]
Announcing the new Android 0.9 SDK beta!
http://android-developers.blogspot.com/2008/08/announcing-beta-release-of-android-sdk.html
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to