[英]Difference between Intent.ACTION_GET_CONTENT and Intent.ACTION_PICK
I'm trying to let the user choose any image that they want on their device to use as a wallpaper in this wallpaper application I'm building. 我试图让用户在他的设备上选择他们想要的任何图像作为我正在构建的壁纸应用程序中的壁纸。 For some reason when I write: 出于某种原因,我写道:
Intent myIntent = new Intent(Intent.ACTION_PICK);
myIntent.setType("image/*");
startActivityForResult(myIntent, 100);
I go straight into the gallery, but when I write: 我直接进入画廊,但是当我写道:
Intent myIntent = new Intent(Intent.ACTION_GET_CONTENT, null);
myIntent.setType("image/*");
startActivityForResult(myIntent, 100);
I get to choose from Gallery, or Google Drive. 我可以选择图库或Google云端硬盘。 What is the best way to let the user choose what app to retrieve the picture from every time? 让用户选择每次检索图片的应用程序的最佳方法是什么? Or why do those two different intent constants make a difference? 或者为什么这两个不同的意图常数有所不同?
Your first Intent
is invalid. 您的第一个Intent
无效。 The protocol for ACTION_PICK
requires you to supply a Uri
indicating the collection you are picking from. ACTION_PICK
的协议要求您提供一个Uri
指示您要从中挑选的集合。
What is the best way to let the user choose what app to retrieve the picture from every time? 让用户选择每次检索图片的应用程序的最佳方法是什么?
If you want the user to choose something based on MIME type, use ACTION_GET_CONTENT
. 如果您希望用户根据MIME类型选择内容,请使用ACTION_GET_CONTENT
。
If you have some specific collection (identified by a Uri
) that you want the user to pick from, use ACTION_PICK
. 如果您有一些您希望用户选择的特定集合(由Uri
标识),请使用ACTION_PICK
。
In case of a tie, go with ACTION_GET_CONTENT
. 如果出现平局,请使用ACTION_GET_CONTENT
。 While ACTION_PICK
is not formally deprecated, Dianne Hackborn recommends ACTION_GET_CONTENT
. 虽然ACTION_PICK
尚未正式弃用,但Dianne ACTION_GET_CONTENT
建议使用ACTION_GET_CONTENT
。
The modern action is ACTION_GET_CONTENT
, which is much better supported , 现代动作是ACTION_GET_CONTENT
, 它得到了更好的支持 ,
ACTION_PICK
: ACTION_PICK
:
Activity Action: Pick an item from the data, returning what was selected. 活动操作:从数据中选择一个项目,返回所选内容。
Input: getData() is URI containing a directory of data (vnd.android.cursor.dir/*) from which to pick an item. 输入: getData()是包含数据目录(vnd.android.cursor.dir / *)的URI,用于从中选择项目。
Output: The URI of the item that was picked. 输出:已拾取项目的URI。
Constant Value: "android.intent.action.PICK" 常量值: “android.intent.action.PICK”
Difference :- 差异 : -
Activity Action: Allow the user to select a particular kind of data and return it . 活动操作:允许用户选择特定类型的数据并将其返回 。
This is different than ACTION_PICK in that here we just say what kind of data is desired, not a URI of existing data from which the user can pick. 这与ACTION_PICK的不同之处在于,我们只是说出需要什么类型的数据, 而不是用户可以从中选择的现有数据的URI 。
A ACTION_GET_CONTENT
could allow the user to create the data as it runs (for example taking a picture or recording a sound ), let them browse over the web and download the desired data, etc. A ACTION_GET_CONTENT
可以允许用户在运行时创建数据 (例如拍照或录制声音 ),让他们浏览网页并下载所需数据等。
Reference http://developer.android.com/reference/android/content/Intent.html#ACTION_GET_CONTENT 参考 http://developer.android.com/reference/android/content/Intent.html#ACTION_GET_CONTENT
public static final String ACTION_GET_CONTENT
Added in API level 1 在API级别1中添加
Activity Action: Allow the user to select a particular kind of data and return it. 活动操作:允许用户选择特定类型的数据并将其返回。 This is different than ACTION_PICK in that here we just say what kind of data is desired, not a URI of existing data from which the user can pick. 这与ACTION_PICK的不同之处在于,我们只是说出需要什么类型的数据,而不是用户可以从中选择的现有数据的URI。 A ACTION_GET_CONTENT could allow the user to create the data as it runs (for example taking a picture or recording a sound), let them browse over the web and download the desired data, etc. ACTION_GET_CONTENT可以允许用户在运行时创建数据(例如拍照或录制声音),让他们浏览网页并下载所需数据等。
via http://developer.android.com/reference/android/content/Intent.html#ACTION_GET_CONTENT 通过http://developer.android.com/reference/android/content/Intent.html#ACTION_GET_CONTENT
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.