Android中使用Intent打开本地图库


1.
 //打开系统相册
 Intent intent = new Intent(
        Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent, Code.REQUEST_CODE);
2.
//接收选择的图片
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if(Code.REQUEST_CODE == requestCode && Activity.RESULT_OK == resultCode && null != data){
        Uri selectImageUri  = data.getData();
        String[] filePathColumn = new String[]{MediaStore.Images.Media.DATA};//要查询的列
        Cursor cursor = getContentResolver().query(selectImageUri,filePathColumn,null,null,null);
        String pirPath = null;
        while(cursor.moveToNext()){
            pirPath = cursor.getString(cursor.getColumnIndex(filePathColumn[0]));//所选择的图片路径
        }
        cursor.close();
}

你可能感兴趣的:(Android)