关于android 5.0调用系统相册闪退

来源:互联网 发布:mysql 清空数据库表 编辑:程序博客网 时间:2024/05/01 13:56

最近做的一个项目中需要调用本地相册,本以为是一个很简单的要求。但是当我在android5.0上运行的时候打开相册,APP闪退。

Android调用本地相册,Intent.ACTION_GET_CONTENT和 Intent.ACTION_PICK都是打开本地相册的两种意图活动。这两种方法在android5.0以前使用后得到的结果都一样。但是在android5.0之后,这两种打开本地相册的方式有了明显的区别。


用Intent.ACTION_GET_CONTENT打开android5.0的相册时,显示的是文件的形式,点击一个文件夹之后并没有打开显示图片,而是提示APP闪退。而用 Intent.ACTION_PICK,打开android5.0的本地相册显示的是每一张图片可以随时返回图片的URL。

public static final String ACTION_PICK

Added in API level 1

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.

Constant Value: "android.intent.action.PICK"             

这是ACTION_PICK的API解释。     大意就是从数据中选着一个item,返回被选中的值。

public static final String ACTION_GET_CONTENT

Added in API level 1

Activity Action: Allow the user to select a particular kind of data and return it. This is different thanACTION_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. An 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. 

API中也解释道和ACTION_PICK的不同,返回的是什么样的数据,不是用户想要选着的具体URl.


虽然API有所解释但在android5.0以前这两个活动的结果是一样的,android5.0后才具体的体现了这两种的区别。所以建议各位如果在有打开本地相册选取图片的时候选着ACTION_PICK活动。 

有知道这两种ACTION在android5.0才存在区别的,请留言告知。 

以上仅是个人观点,有不对的地方情留言改正。


2 0