我用传统的方法从系统图库选取图片没报错,在4.4版本以下的虚拟机可以正常运行,但是在4.4版本的系统就会出错,上网查了一下资料,说是4.4返回的URI和以前的不一样,求解4.4以上怎么获取文件路径?下面是返回后处理URI的方法
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 1 && resultCode == RESULT_OK && null != data) {
Uri selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
cursor.close();
ImageView imageView = (ImageView) findViewById(R.id.iv2);
imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));
}
} |
|