打开所有图像的图库

时间:2016-04-12 09:33:11

标签: android

我正在尝试为外部文件打开图库,但它只显示内部文件。

    if (requestCode == 0 && resultCode == RESULT_OK && null != data) {
            Uri selectedImage = data.getData();
            String[] filePathColumn = {MediaStore.Images.Media.DATA};
            Cursor cursor = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                    filePathColumn, null, null, null);
            cursor.moveToFirst();
            int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
            String picturePath = cursor.getString(columnIndex);
            cursor.close();

}

1 个答案:

答案 0 :(得分:0)

试试这段代码:

要打开图库:

public String getPath(Uri uri) {
String[] projection = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(uri, projection, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);}

获取文件的实际路径:

<div layout="column">
    <span>{{property.name}}-Error:{{roomForm['property'+property.id].$error}}</span>
    <span>{{property.name}}-Dirty:{{roomForm['property'+property.id].$dirty}}</span>
    <span>{{property.name}}-Touched:{{roomForm['property'+property.id].$touched}}</span>
    <span>{{property.name}}-Pristine:{{roomForm['property'+property.id].$pristine}}</span>
    <span>{{property.name}}-Valid:{{roomForm['property'+property.id].$valid}}</span>
</div>

希望这可以帮助你。