207_intent启动相册
//先创建一个intent //给一个action,再给一个uri//action给Intent.ACTION_PICK//uri给android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URIIntent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
//然后设置一个type为"image/*" intent.setType("image/*");
//启动activity startActivityForResult(intent, 0);
这里我们只是启动了相册,还没有什么实际的操作
以后我们再说选择图片的事情
这里我们看一下涉及到的几个源码
首先是 Intent.ACTION_PICK
来看看源码
/** * Activity Action: Pick an item from the data, returning what was selected. * <p>Input: {@link #getData} is URI containing a directory of data * (vnd.android.cursor.dir/*) from which to pick an item. * <p>Output: The URI of the item that was picked. */ @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) public static final String ACTION_PICK = "android.intent.action.PICK";
来翻译一下:
activity action: 从data里面挑选一个项目,返回被选择的那个
Input输入:包含目录的uri
output输出:被选择的项目的uri
再看看android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI
/** * The content:// style URI for the "primary" external storage * volume. */ public static final Uri EXTERNAL_CONTENT_URI = getContentUri("external");/** * Get the content:// style URI for the image media table on the * given volume. * * @param volumeName the name of the volume to get the URI for * @return the URI to the image media table on the given volume */ public static Uri getContentUri(String volumeName) { return Uri.parse(CONTENT_AUTHORITY_SLASH + volumeName + "/images/media"); }
其实就是指向相册的uri