相关疑难解决方法(0)

使用新的Google相册应用选择照片已损坏

我的应用程序可以从库中选择照片.我想要从这个选择中获取文件路径.

这是创建选择照片的意图的代码:

    Intent photoPickerIntent = new Intent(Intent.ACTION_PICK,
        MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    photoPickerIntent.setType("image/*");
    startActivityForResult(photoPickerIntent, INTENT_REQUEST_CODE_SELECT_PHOTO);
Run Code Online (Sandbox Code Playgroud)

这是从URI获取文件路径的代码:

    Cursor cursor = null;
    String path = null;
    try {
        String[] projection = { MediaStore.Images.Media.DATA };
        cursor = context.getContentResolver().query(contentUri, projection, null, null, null);
        int columnIndex = cursor.getColumnIndexOrThrow(projection[0]);
        cursor.moveToFirst();
        path = cursor.getString(columnIndex);
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
    return path;
Run Code Online (Sandbox Code Playgroud)

在昨天更新Google相册应用之前,一切都运转良好.path解析URI后现在为null.

URI类似于: content://com.google.android.apps.photos.contentprovider/0/1/content%3A%2F%2Fmedia%2Fexternal%2Fimages%2Fmedia%2F75209/ACTUAL

我还试图用Intent.ACTION_GET_CONTENT动作创建意图 - 没有运气.

android android-intent android-gallery google-photos

47
推荐指数
2
解决办法
2万
查看次数