简体   繁体   English

Intent.ACTION_GET_CONTENT和Intent.ACTION_PICK之间的区别

[英]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.

相关问题 无法从Intent获取正确的URI。ACTION_GET_CONTENT - Not getting correct URI from Intent.ACTION_GET_CONTENT 如何从 Intent.ACTION_GET_CONTENT 获取完整路径? - How to get full path from Intent.ACTION_GET_CONTENT? 如何使用Intent.ACTION_PICK响应,但是没有活动? - How to use Intent.ACTION_PICK with response, but withou Activity? 如何使用intent.ACTION_PICK打开系统联系人并选择一些联系人,而不仅仅是选择一个? - How to use intent.ACTION_PICK to open the system contacts and pick some contacts, but not just pick one? Android:如何从Intent.ACTION_GET_CONTENT获得的URI中检索视频缩略图? - Android: How to retrieve video Thumbnail from URI obtained from Intent.ACTION_GET_CONTENT? 为Android的Intent关闭页面过渡动画。ACTION_PICK - Turning off page transition animations for Android's Intent.ACTION_PICK 未找到处理 Intent{typ=andrid.intent.action.PICK} 的活动 - No Activity found to handle Intent{typ=andrid.intent.action.PICK} android.content.ActivityNotFoundException:未找到任何处理Intent的活动{act = android.intent.action.GET_CONTENT - android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.GET_CONTENT Android Intent ACTION_GET_CONTENT 不返回文件扩展名 - Android Intent ACTION_GET_CONTENT does not return extension of file OnActivityResult 有时不会在 ACTION_GET_CONTENT 意图后调用 - OnActivityResult sometimes not called after ACTION_GET_CONTENT intent
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM