[Android] ACTION_GET_CONTENT与ACTION_PICK的区别
2014-09-22 10:54
302 查看
参考:AndroidSDK/docs/reference/android/content/Intent
看到相关代码,对这两个参数的区别有点搞不清。
原文地址请保留/article/5262208.html
现在知道的是new Intent(Intent.ACTION_GET_CONTENT, null)必须要setType("type/后缀"),否则会会弹出异常FATAL EXCEPTION:main android.content.ActivityNotFoundException,
ACTION_PICK可以不用setType()。但建议设置一下属性,因为他们都是通过属性来打开相应的应用程序。
专门从文档摘下来说明,放一起比较下,以后再看这方面的说明也方便。就不翻译了。程序猿嘛,总得看的懂英文文档吧。
Activity Action: Allow the user to select a particular kind of data and return it. This is different than
There are two main ways to use this action: if you want a specific kind of data, such as a person contact, you set the MIME type to the kind of data you want and launch it with
You may also be interested in any of a set of types of content the user can pick. For example, an e-mail application that wants to allow the user to add an attachment to an e-mail message can use this action to bring up a list of all of the types of content the user can attach.
In this case, you should wrap the GET_CONTENT intent with a chooser (through
When using such a broad GET_CONTENT action, it is often desirable to only pick from data that can be represented as a stream. This is accomplished by requiring the
Callers can optionally specify
Input:
Output: The URI of the item that was picked. This must be a content: URI so that any receiver can access it.
Constant Value: "android.intent.action.GET_CONTENT"
Activity Action: Pick an item from the data, returning what was selected.
Input:
Output: The URI of the item that was picked.
Constant Value: "android.intent.action.PICK"
看到相关代码,对这两个参数的区别有点搞不清。
原文地址请保留/article/5262208.html
现在知道的是new Intent(Intent.ACTION_GET_CONTENT, null)必须要setType("type/后缀"),否则会会弹出异常FATAL EXCEPTION:main android.content.ActivityNotFoundException,
ACTION_PICK可以不用setType()。但建议设置一下属性,因为他们都是通过属性来打开相应的应用程序。
专门从文档摘下来说明,放一起比较下,以后再看这方面的说明也方便。就不翻译了。程序猿嘛,总得看的懂英文文档吧。
public static final String ACTION_GET_CONTENT
Added in API level 1Activity Action: Allow the user to select a particular kind of data and return it. This is different than
ACTION_PICKin that here we just say what kind of data is desired, not a URI of existing data from which the user can pick. 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.
There are two main ways to use this action: if you want a specific kind of data, such as a person contact, you set the MIME type to the kind of data you want and launch it with
startActivity(Intent). The system will then launch the best application to select that kind of data for you.
You may also be interested in any of a set of types of content the user can pick. For example, an e-mail application that wants to allow the user to add an attachment to an e-mail message can use this action to bring up a list of all of the types of content the user can attach.
In this case, you should wrap the GET_CONTENT intent with a chooser (through
createChooser(Intent, CharSequence)), which will give the proper interface for the user to pick how to send your data and allow you to specify a prompt indicating what they are doing. You will usually specify a broad MIME type (such as image/* or */*), resulting in a broad range of content types the user can select from.
When using such a broad GET_CONTENT action, it is often desirable to only pick from data that can be represented as a stream. This is accomplished by requiring the
CATEGORY_OPENABLEin the Intent.
Callers can optionally specify
EXTRA_LOCAL_ONLYto request that the launched content chooser only returns results representing data that is locally available on the device. For example, if this extra is set to true then an image picker should not show any pictures that are available from a remote server but not already on the local device (thus requiring they be downloaded when opened).
Input:
getType()is the desired MIME type to retrieve. Note that no URI is supplied in the intent, as there are no constraints on where the returned data originally comes from. You may also include the
CATEGORY_OPENABLEif you can only accept data that can be opened as a stream. You may use
EXTRA_LOCAL_ONLYto limit content selection to local data.
Output: The URI of the item that was picked. This must be a content: URI so that any receiver can access it.
Constant Value: "android.intent.action.GET_CONTENT"
public static final String ACTION_PICK
Added in API level 1Activity 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.
Output: The URI of the item that was picked.
Constant Value: "android.intent.action.PICK"
相关文章推荐
- Android获取本地图片之ACTION_GET_CONTENT与ACTION_PICK区别
- Android 巧用Itent.ACTION_PICK和Intent.ACTION_GET_CONTENT(一)
- Android 巧用Itent.ACTION_PICK和Intent.ACTION_GET_CONTENT(三)
- Android 巧用Itent.ACTION_PICK和Intent.ACTION_GET_CONTENT(二)
- Intent.ACTION_GET_CONTENT和Intent.ACTION_PICK的使用区别
- android之Itent.ACTION_PICK Intent.ACTION_GET_CONTENT妙用
- android之Itent.ACTION_PICK Intent.ACTION_GET_CONTENT妙用
- Android 巧用Itent.ACTION_PICK和Intent.ACTION_GET_CONTENT
- Android——ACTION_GET_CONTENT和ACTION_PICK
- android之Itent.ACTION_PICK Intent.ACTION_GET_CONTENT妙用
- Android开发笔记——Itent.ACTION_PICK Intent.ACTION_GET_CONTENT妙用
- Android 巧用Itent.ACTION_PICK和Intent.ACTION_GET_CONTENT(三)
- 81ACTION_GET_CONTENT和ACTION_PICK的区别
- Intent.ACTION_PICK和Intent.ACTION_GET_CONTENT 调用系统联系人;图片;音乐;视频;
- android中this、getAppliaction()、context的区别。
- android MotionEvent getAction,getActionMasked,getActionIndex区别
- android之Itent.ACTION_PICK Intent.ACTION_GET_CONTENT妙用
- ACTION_PICK与ACTION_GET_CONTENT
- Intent.ACRION.view , Intent.Action.pick intent.action.get_content几个的理解
- android之Itent.ACTION_PICK Intent.ACTION_GET_CONTENT妙用