我正在尝试打开画廊并从那里选择图像。我得到了从相机捕获的所有图像的路径,但无法获得从 Facebook/picassa 等下载的图像的真实路径。它给出的路径就像https://lh3.googleusercontent.com/XNzSBp0MycQ/TigFxMIWn2I/AAAAAAAAAAAAg/YJPWAWmGOy0/I/11%252520-%2525201.jpg 即使它在画廊。
这是我的代码::
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"),SELECT_IMAGE);
我正在使用以下代码来获取路径
Uri selectedImageUri = data.getData();
String selectedImagePath = getPath(selectedImageUri);
public String getPath(Uri uri) {
int columnIndex = 0;
String[] projection = { MediaColumns.DATA };
Cursor cursor = managedQuery(uri, projection, null, null, null);
if (cursor != null) {
columnIndex = cursor.getColumnIndexOrThrow(MediaColumns.DATA);
cursor.moveToFirst();
String imagePath = cursor.getString(columnIndex);
return imagePath;
} else {
return null;
}