在安卓系统中将真实路径格式转换为Uri

9
例如:

真实路径是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。


它可以帮助你 https://dev59.com/qHA75IYBdhLWcg3w9-Sx#11603841 - CoDe
2个回答

14

试一试这个:

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

使用相机拍照并将其存储在SD卡文件夹中,例如mnt/sdcard/image.jpg。我需要使用Hackbook将该图片上传到Facebook。图库中的图片可以上传,但相机拍摄的图片无法正常工作...... - yoga
我有真实路径,如果可能将Uri路径转换一下...有什么想法请帮忙...谢谢。 - yoga
适用于三星Tab E。 - farhan patel

0

1
this answer is opposite - Iftikar Urrhman Khan

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接