[Android] ACTION_GET_CONTENT与ACTION_PICK的区别
参考:AndroidSDK/docs/reference/android/content/Intent
看到相关代码,对这两个参数的区别有点搞不清。
原文地址请保留http://www.cnblogs.com/rossoneri/p/3985597.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
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. 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_OPENABLE
in the Intent.
Callers can optionally specify EXTRA_LOCAL_ONLY
to 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_OPENABLE
if you can only accept data that can be opened as a stream. You may use EXTRA_LOCAL_ONLY
to 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.
public static final String 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.
Output: The URI of the item that was picked.
[Android] ACTION_GET_CONTENT与ACTION_PICK的区别的更多相关文章
- android脚步---Itent.ACTION_PICK ,startActivityForResult
public void onClick(View v) { // TODO Auto-generated method stub Intent intent = new Intent(Intent.A ...
- Android SingleTask与SingleInstance的区别
Android SingleTask与SingleInstance的区别 原文地址 现有2个项目,taskA.taskB.taskA负责调用taskB中指定的界面. taskB中有3个界面,a.b.c ...
- Xamarin.Form与Xamarin.Android或Xamarin.IOS的区别简述
Xamarin.Form与Xamarin.Android或Xamarin.IOS的区别简述: 可能刚刚接触Xamarin的人来说,对于这个概念比较的模糊,认为这说的不都是同一个东西吗?事实并不是这样的 ...
- Android(四)-JVM与DVM区别
JVM与DVM区别 1.由来 Android是基于java的既然java已经有了java虚拟机,为什么android还要弄一个DVM了?最重要的就是版权问题,一开始就是用的 JVM,没过多久就被SUN ...
- android之Itent.ACTION_PICK Intent.ACTION_GET_CONTENT妙用
你是不是很多时候,想从弹出的电话本姓名列表中中查找到某个人,然后再获取该人的详细信息呢? 你是不是想选择从弹出的列表中选择一张图片,然后将其进行进一步的操作呢? 如果,你想,那你是不是很像知道,我们应 ...
- Android Parcelable和Serializable的区别,androidparcelable
本文主要介绍Parcelable和Serializable的作用.效率.区别及选择,关于Serializable的介绍见Java 序列化的高级认识. 1.作用 Serializable的作用是为了保存 ...
- [android界面]android中src和background区别——前景与背景
ImageView中XML属性src和background的区别: background会根据ImageView组件给定的长宽进行拉伸,而src就存放的是原图的大小,不会进行拉伸.src是图片内容(前 ...
- Android title和actionbar的区别
我想在一个页面的顶端放入两个按钮,应该用title还是actionbar.他们两个什么区别?分别该什么时候用? 答: android title 是UI上的一小部分,它支持Text和Color,你可以 ...
- android:ImageView 和ImageButton的区别
1.继承不同: java.lang.Object ↳ android.view.View ↳android.widget.ImageView ↳ android.widget.ImageButton ...
随机推荐
- MySQL Cluster 日常维护
在前面几篇文章已经详细介绍了MySQL Cluster的搭建,配置讲解.而且相信大家都掌握了基本用法.现在我们来看看Cluster的日常维护.熟悉日常维护,将有助于工作中更好的管理和使用Cluster ...
- SpringBoot入门 (九) MQ使用
本文记录学习在Spring Boot中使用MQ. 一 什么是MQ MQ全称(Message Queue)又名消息队列,是一种异步通讯的中间件.它的作用类似于邮局,发信人(生产者)只需要将信(消息)交给 ...
- eclipse安装quick text search插件,全文搜索
主要有两种方法 1.InstaSearch 同样可以做到workspace下的全文搜索 可以使用eclipse marktplace中搜索instaSearch,与普通软件安装类似 安装成功后的界面如 ...
- k8s使用nfs动态存储
1.Kubernetes集群管理员通过提供不同的存储类,可以满足用户不同的服务质量级别.备份策略和任意策略要求的存储需求.动态存储卷供应使用StorageClass进行实现,其允许存储卷按需被创建.如 ...
- spring AOP 之三:使用@AspectJ定义切入点
@AspectJ相关文章 <spring AOP 之二:@AspectJ注解的3种配置> <spring AOP 之三:使用@AspectJ定义切入点> <spring ...
- springboot redis 缓存跨域丢失问题
对于前后端分离的项目,在开发阶段经常会遇到跨域的问题. 1.首先,对于后台的处理方式,第一种是用 @CrossOrigin 注解,@crossorigin是后端SpringMVC框架(需4.2版本以上 ...
- 百度前端技术学院-task1.8源代码以及个人总结
通过这次任务的练习我学到了很多,现将所学到的以及遇到的问题总结如下. 源码地址:http://pan.baidu.com/s/1kVB2VZL 下面出现的代码,都是摘自这个上面的源码 1.终于明白了a ...
- 进程监控工具supervisor
supervisor是一个python编写的进程管理工具, 可以方便的管理和监控进程. supervisor分为服务端supervisord和客户端supervisorctl. supervisor由 ...
- Netty 内存回收之 noCleaner 策略
前言 对于堆外内存,使用 System.gc() 是不靠谱的,依赖老年代 FGC 也是不靠谱的,而且大部分调优指南都设置了 -DisableExplicitGC 禁用 System.gc().所以主动 ...
- 并发编程之 Thread 类过期方法和常用方法
前言 在 Java 刚诞生时,Thread 类就已经有了很多方法,但这些方法由于一些原因(有一些明显的bug或者设计不合理)有些已经废弃了,但是他们的方法名却是非常的好,真的是浪费.我们在进行并发必编 ...