单的意图,让用户拍摄照片或从库中的Andr​​oid挑图像意图、库中、图像、照片

2023-09-13 02:24:13 作者:ら只願得一人心゛

我正在开发适用于Android 2.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.

如果我直接进入使用MediaStore.ACTION_IM​​AGE_CAPTURE相机模式,则没有选择下降到画廊。

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

如果我直接去使用Intent.ACTION_PICK然后我可以选择一个图像,但如果我点击拍照键(在画廊的右上角),然后一个新的相机意图解雇的画廊。那么,是不是直接把我的应用程序返回拍摄的任何图片。 (当然,你可以preSS后退按钮回落到从那里的画廊,并选择图像,但这是一个额外的不必要的一步,是不是在所有直观)。

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?

推荐答案

更新:对方回答,使用 EXTRA_INITIAL_INTENTS ,是一个更好的在此刻。在我写我的答案的时候, EXTRA_INITIAL_INTENTS 还不存在,因为它增加了在API级别5。

UPDATE: The other answer, using EXTRA_INITIAL_INTENTS, is a better one at this point. At the time I wrote my answer, EXTRA_INITIAL_INTENTS did not yet exist, as it was added in API Level 5.

那么,有没有一种既结合或   我要去必须提供一个菜单   做一个或另一个从我   应用程序?

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?

开发人员旁边,你会觉得画廊应该允许您选择从本地库,否则跳了到Flickr进行选择从那里。另一个开发商会认为相机不应该只允许通过相机拍照,而是通过从库中选择的东西,从你预想的方式反转的事情拍照。然而,另一个开发人员认为,画廊应该允许从本地画廊,或Flickr,或相机,或网络连接的网络摄像头采摘。还有一个开发者会认为该画廊是愚蠢的,用户应该只通过一个文件浏览器接的文件。等等。

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.

所有这一切都在一个环境(手机),其中闪存的操作系统是在premium。

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

因此​​,恕我直言,这是不完全令人震惊的是核心的Andr​​oid团队当选为基石,为您装配您认为合适的,而不是试图去适应每一种可能的模式。

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.