简体   繁体   English

Android-如何执行回调函数以从图库中选择路径图像

[英]Android - How to do a callback function to get path image selected from gallery

I need to call a function when the user select an image from gallery and get the path of the selected image. 当用户从图库中选择图像并获取所选图像的路径时,我需要调用一个函数。 Following my code, activated by onclick: 按照我的代码,通过onclick激活:

protected Bitmap bitmap;
public void onclick(View v){
        Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);        
        startActivityForResult(i, STATUS);
}

I need a callback function because I want to store the selected image to the variable bitmap like following: 我需要一个回调函数,因为我想将所选图像存储到变量位图中,如下所示:

Bitmap bitmap = BitmapFactory.decodeFile(PATH_SELECTED_IMAGE);

How to do a callback function and get the path of selected image? 如何做一个回调函数并获取所选图像的路径?

您可以通过重写onActivityResult()方法来实现此目的,在该方法中,您需要检查调用画廊意图时给出的请求代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 获取从图库中选择的图像路径 - Get image path selected from the gallery 如何获取从 android 10 上的图库中选择的视频的路径 - How to get the path of a video which is selected from gallery on android 10 如何从图像库中获取所选图像的名称 android studio - how to get the name of a selected image from gallery of images android studio 如何从图库中选择的图像中获取图像 URI。 安卓 5.0.2? - How to Get Image URI from Image selected From gallery. Android 5.0.2? 如何在 android 工作室中使用声音云从图库中选择裁剪图像的 uri - how to get the uri of a cropped image selected from gallery using sound cloud in android studio 在Android中获取所选图库图像的文件路径和文件名 - Get filepath and filename of selected gallery image in Android 如何获取从图库中选择的图像的目录和文件名 - How to get Directory and file name of an image selected from gallery 无法在Android中显示从图库中选择的图像 - Failed to show selected image from gallery in android 如何在Android中捕获图像以及如何从图库中获取图像 - How to capture image and how to get image from gallery in android 如何在android 10及更高版本的android中获取捕获图像和图库图像的真实路径 - How to get real path of capture image and gallery image in android in android 10 and above
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM