views:

846

answers:

1

I'm developing an app for Android 2.1 upwards. I want to enable my users to select a profile picture within my app (I'm not using the contacts framework).

The ideal solution would be to fire an intent that enables the user to select an image from the gallery, but if an appropriate image is not available then use the camera to take a picture (or vice-versa i.e. allow user to take picture but if they know they already have a suitable image already, let them drop into the gallery and pick said image).

Currently I can do one or the other but not both.

If I go directly into camera mode using MediaStore.ACTION_IMAGE_CAPTURE then there is no option to drop into the gallery.

If I go directly to the gallery using Intent.ACTION_PICK then I can pick an image but if I click the camera button (in top right hand corner of gallery) then a new camera intent is fired. So, any picture that is taken is not returned directly to my application. (Sure you can press the back button to drop back into the gallery and select image from there but this is an extra unnecessary step and is not at all intuitive).

So is there a way to combine both or am I going to have to offer a menu to do one or the other from within my application? Seems like it would be a common use case...surely I'm missing something?

+2  A: 

So is there a way to combine both or am I going to have to offer a menu to do one or the other from within my application?

Write your own gallery that has the features you desire.

I would think a menu would be simpler.

Seems like it would be a common use case...surely I'm missing something?

The developer next to you will think the gallery should allow you to pick from the local gallery or else hop out to Flickr to make a selection from there. Another developer will think the camera should not only allow to "take a picture" via the camera but to "take a picture" via choosing something from the gallery, inverting things from the way you envision it. Yet another developer will think that the gallery should allow picking from the local gallery, or Flickr, or the camera, or a network-attached webcam. Still another developer will think that the gallery is stupid and users should just pick files via a file explorer. And so on.

All of this in an environment (mobile phones) where flash for the OS is at a premium.

Hence, IMHO, it is not completely shocking that the core Android team elected to provide building blocks for you to assemble as you see fit, rather than trying to accommodate every possible pattern.

CommonsWare
OK, thanks Mark. As an avid reader of your commonsware books, I'll take that as a definitive answer. For now, I'll implement a menu in my app and will keep my fingers crossed that G produce something for me as part of the anticipated Froyo release next month. The Gallery app is so nice on 2.1, I'd love to be able to reuse / customise it for this scenario.
Damian
Yeah, your notion (`ACTION_PICK` followed by camera icon would take a picture, add it, and return the picture) certainly isn't crazy. You might want to poke a bit at the pre-Froyo code for Gallery and see what they're doing there.
CommonsWare
Generally for the case where you want to say "i want the user to select for me X kind of content of some type," you would use GET_CONTENT. For example here you would use GET_CONTENT with type image/*, which would first present the user a list of things from which they can select images (gallery, camera, and whatever other apps have images to offer).
hackbod