我必须实现一个应用程序,一旦用户从电话库部分打开他/她的任何图像,就会在服务器上上传图像。我的问题是如何获取图像路径? 提前致谢
答案 0 :(得分:0)
首先调用此意图从图库中选择图像:
private static final int SELECT_PHOTO = 100;
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.setType("image/*");
startActivityForResult(photoPickerIntent, SELECT_PHOTO);
完成图库中的选择图片后,它会自动调用此onActivityResult
方法:
@Override
protected void onActivityResult(int requestCode, int resultCode,
Intent imageReturnedIntent) {
super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
switch (requestCode) {
case SELECT_PHOTO:
if (resultCode == RESULT_OK) {
Uri selectedImage = imageReturnedIntent.getData();
try {
yourImageView.setImageBitmap(decodeUri(selectedImage));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}
}
您将在selectedImage
变量中获取图像路径。
感谢。