Android选择相册里的图片并获取准确的路径

1、这个需要配合上一次的代码

2、详情了解:https://blog.nhl520.cn/index.php/2022/09/28/android%e9%80%89%e6%8b%a9%e7%9b%b8%e5%86%8c%e9%87%8c%e7%9a%84%e5%9b%be%e7%89%87/

3、在if (data != null) { 下面加入以下代码

//显示图片路径
 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);
System.out.println(picturePath);

4、最后控制台输入图片的路径。

二哈

文章作者信息...

留下你的评论

*评论支持代码高亮<pre class="prettyprint linenums">代码</pre>

相关推荐