【发布时间】:2015-08-12 04:05:37
【问题描述】:
我的应用可以从库中选择照片。正是我想要这个选择的文件路径。
这是创建选择照片意图的代码:
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK,
MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
photoPickerIntent.setType("image/*");
startActivityForResult(photoPickerIntent, INTENT_REQUEST_CODE_SELECT_PHOTO);
这是从 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;
在昨天更新 Google 相册应用之前,一切正常。
现在path解析URI后为空。
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