我正在尝试将图像文件的完整路径作为字符串获取,但它不起作用。我只是得到像“内容:/外部/媒体/图像/1”这样的结果。这绝对不是正确的道路。如何获得正确的路径,包括文件扩展名?
这是我到目前为止所尝试的:
public void onClick(View arg0) {
switch (arg0.getId()) {
case R.id.btnGetImage:
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
startActivityForResult(Intent.createChooser(intent, "Select A Picture"),
PHOTO_GALLERY);
break;
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch(requestCode){
case PHOTO_GALLERY:
if (resultCode == RESULT_OK) {
File file = new File(data.getDataString());
String imagePath = file.getAbsolutePath();
break;
}
}
}