乌里转换为字符串和字符串到乌里 [英] Convert Uri to String and String to Uri

查看:467
本文介绍了乌里转换为字符串和字符串到乌里的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了一些应用程序,允许选择的图像从SD卡,并保存到数据库,并将该值ImageView的。我需要知道的方式转换的URI字符串,字符串URI。现在我用getEn codeDPATH()开放的方法,但是,例如,该code不工作:

  ImageView的IV =(ImageView的)findViewById(R.id.imageView1);
开放的我们的uri = Uri.parse(/外部/图片/媒体/ 470939);
Log.e(uri1,uri.toString());
iv.setImageURI(URI);
 

所以我不知道我能救乌里到数据库,并从保存的值来创建一个新的URI。请帮我解决它。

解决方案
  

我需要知道的方式转换的URI字符串,字符串URI。

使用的toString()来转换乌里字符串。使用 Uri.parse()来转换字符串乌里

  

这code不起作用

这是不是再一个乌里的presentation一个有效的字符串。 A 乌里有一个计划,而/外部/图片/媒体/ 470939没有一个方案。

I'm developing some Application which allows select image from SD Card, save it into database and set this value for ImageView. I need to know way for converting uri to string and string to uri. Now I used getEncodedPath() method of Uri, but, for example, this code doesn't work:

ImageView iv=(ImageView)findViewById(R.id.imageView1);
Uri uri=Uri.parse("/external/images/media/470939");
Log.e("uri1", uri.toString());
iv.setImageURI(uri);

Therefore I don't know how I can save Uri into database and create a new Uri from saved value. Please, help me to fix it.

解决方案

I need to know way for converting uri to string and string to uri.

Use toString() to convert a Uri to a String. Use Uri.parse() to convert a String to a Uri.

this code doesn't work

That is not a valid string representation of a Uri. A Uri has a scheme, and "/external/images/media/470939" does not have a scheme.

这篇关于乌里转换为字符串和字符串到乌里的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆