【问题标题】:Convert real path format to Uri in android在android中将真实路径格式转换为Uri
【发布时间】:2023-03-23 11:22:02
【问题描述】:

例如

真正的路径是mnt/sdcard/image_1.jpg Uri 路径是 content://media/external/images/media/140 这样的

  Uri photoUri =Uri.parse("content://media/external/images/media/140");
                                            Log.d("selectedphoto",""+photoUri);
               selectedImagePath = getPath(photoUri);

     public String getPath(Uri uri) {
            String[] projection = { MediaStore.Images.Media.DATA };
            Cursor cursor = managedQuery(uri, projection, null, null, null);
            int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
            cursor.moveToFirst();



    return cursor.getString(column_index);
    }

在上面的代码中,我将 Uri 转换为真实路径,但不知道如何将真实路径转换为 ​​Uri

【问题讨论】:

标签: android android-intent


【解决方案1】:

试试这个:

Uri.fromFile(new File("/sdcard/cats.jpg"));

【讨论】:

  • 使用相机拍照以存储 sdcard 文件夹,如 mnt/sdcard/image.jpg 我需要使用 hackbook 将该照片上传到 facebook.. 已上传图库图像但相机图像无法正常工作.... .....
  • 如果可以转换 Uri 路径,我有真正的路径..有任何想法请帮助我.....谢谢
  • 适用于三星标签电子
【解决方案2】:

这将从 MediaProvider、DownloadsProvider 和 ExternalStorageProvider 获取文件路径,同时回退到您提到的非官方 ContentProvider 方法。

https://stackoverflow.com/a/27271131/3758898

【讨论】:

  • 这个答案是相反的
猜你喜欢
  • 2013-11-27
  • 1970-01-01
  • 2015-02-20
  • 2018-12-04
  • 2017-08-09
  • 2013-07-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多