选择多张图片从机器人图库机器人、多张、图库、图片

2023-09-12 01:42:06 作者:欲将心事付瑶琴

所以基本上什么,我想实现的是打开图库在Android和让用户选择多张图片 。现在,这个问题已经被问经常,但我不太满意的答案。主要是因为我发现了一些在去文档有趣的在我的IDE(我回来稍后),因此我不希望使用自定义适配器,但只是香草之一。

So basically what i am trying to achieve is opening the Gallery in Android and let the user select multiple images. Now this question has been asked frequently but i'm not satisfied with the answers. Mainly because i found something interesting in de docs in my IDE (i come back on this later) and thereby i don't want to use a custom adapter but just the vanilla one.

现在我的$ C $下选择一个图像是:

Now my code for selecting one image is:

Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,"Select Picture"), 1);

现在的人,所以和其他网站的西港岛线告诉你,你有2个选项:

Now People on SO and other websites wil tell you you have 2 options:

1)不要使用 ACTION_GET_CONTENT ,但 ACTION_SEND_MULTIPLE 代替。  这一个不工作。根据文档的发送文件,而不是检索而这正是它这一个是。当使用ACTION_SEND_MULTIPLE我打开了我的设备中的窗口,在这里我要选择一个应用程序,以我的数据发送到。这不是我想要的,所以我不知道人们如何得到这个实现这个解决方案..我是否错过了什么?

1) Do not use ACTION_GET_CONTENT but ACTION_SEND_MULTIPLE instead. This one doesn't work. This one is according to the docs for sending files and not retrieving and that's exactly what it does. When using ACTION_SEND_MULTIPLE i got a window opened at my device where i have to select an application to send my data to. That's not what i want, so i wonder how people got this achieved with this solution.. Do i miss something?

2)的实施自定义库。现在,这是我最后的选择,我会考虑,因为恕我直言不是我正在寻找,因为我要的风格是我自己和别人为什么非得你就不能选择在香草画廊多张图片?

2) Implement an custom Gallery. Now this is my last option i will consider because imho it's not what i am searching for because i have to style it myself AND why the heck you just can't select multiple images in the vanilla gallery?

必须有这样的一个选项。现在有趣的事情是什么我心中已经发现是这样的: 的我在 ACTION_GET_CONTENT 的文档说明发现了这个。的

There must be an option for this.. Now the interesting thing what i'v found is this: I found this in the docs description of ACTION_GET_CONTENT.

如果主叫方可以处理多个归还物品(用户表演   多选),那么它可以指定EXTRA_ALLOW_MULTIPLE到   表明这一点。

If the caller can handle multiple returned items (the user performing multiple selection), then it can specify EXTRA_ALLOW_MULTIPLE to indicate this.

这是pretty的有趣。在这里,他们是指它的使用情况下,用户可以选择多个项目?

This is pretty interesting. Here they are referring it to the use case where a user can select multiple items?

后来他们在文档说:

您可以使用EXTRA_ALLOW_MULTIPLE允许用户选择多个   项目。

You may use EXTRA_ALLOW_MULTIPLE to allow the user to select multiple items.

因此​​,这是pretty的明显的对不对?这正是我需要的。但我下面的问题是:我在哪里可以把这个 EXTRA_ALLOW_MULTIPLE ?可悲的是,我不能找到这个任何地方在 developers.android指南,也就是这个没有定义为一个常量,意图类。

So this is pretty obvious right? This is what i need. But my following question is: Where can i put this EXTRA_ALLOW_MULTIPLE? The sad thing is that i can't find this no where in the developers.android guide and also is this not defined as a constant in the INTENT class.

任何人都可以帮我这个 EXTRA_ALLOW_MULTIPLE

Anybody can help me out with this EXTRA_ALLOW_MULTIPLE?

推荐答案

该EXTRA_ALLOW_MULTIPLE选择是通过Intent.putExtra()方法设置的意图:

The EXTRA_ALLOW_MULTIPLE option is set on the intent through the Intent.putExtra() method:

intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);

您code以上应该是这样的:

Your code above should look like this:

Intent intent = new Intent();
intent.setType("image/*");
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,"Select Picture"), 1);

注:EXTRA_ALLOW_MULTIPLE选项仅在Android的API 18和可用的高

Note: the EXTRA_ALLOW_MULTIPLE option is only available in Android API 18 and higher.