0

我无法从所选图像 Uri 中读取数据部分,这发生在某些特定设备 Lg nexus 5 api 6.0.1

所选图像的 Uri

content://com.google.android.apps.photos.contentprovider/-1/1/content://media/external/images/media/200/ORIGINAL/NONE/2077196451

用于从 uri 获取数据的代码

 public static String getDataColumn(Context context, Uri uri, String selection,
                                       String[] selectionArgs) {

        Cursor cursor = null;
        final String column = "_data";
        final String[] projection = {
                column
        };

        try {
            cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs,
                    null);
            if (cursor != null && cursor.moveToFirst()) {
                final int index = cursor.getColumnIndexOrThrow(column);
                return cursor.getString(index);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        finally {
            if (cursor != null)
                cursor.close();
        }
        return null;
    }

权限处理没有问题,提供了必需的权限。

4

0 回答 0