uri,file,path互相转化

2017-12-24 11:43:48

uri转file:


[html] view plain copy print?

  1. file = new File(new URI(uri.toString()));  


uri转path:



[html] view plain copy print?

  1. private String getPath(Uri uri) {  

  2.        String[] projection = {MediaStore.Video.Media.DATA};  

  3.        Cursor cursor = managedQuery(uri, projection, null, null, null);  

  4.        int column_index = cursor  

  5.                .getColumnIndexOrThrow(MediaStore.Audio.Media.DATA);  

  6.        cursor.moveToFirst();  

  7.        return cursor.getString(column_index);  

  8.    }  




file转uri:


[html] view plain copy print?

  1. URI uri = file.toURI();  



file转path:


[html] view plain copy print?

  1. String path = file.getPath()  





path转uri:


[html] view plain copy print?

  1. Uri uri = Uri.parse(path);  


path转file:



[html] view plain copy print?

  1. File file = new File(path)  



  • 2020-12-21 09:00:20

    Window.matchMedia() 方法详解

    matchMedia() 返回一个新的 MediaQueryList 对象,表示指定的媒体查询字符串解析后的结果。 matchMedia() 方法的值可以是任何一个 CSS @media 规则 的特性, 如 min-height, min-width, orientation 等。 MediaQueryList 对象有以下两个属性:

  • 2020-12-21 09:42:42

    iframe.contentWindow 操作iframe

    注:iframe.contentWindow这里,返回的是iframe的window对象,所以后面可以接着调用document方法,再接着调用getElementByTagName。那么就可以对iframe里面的元素进行操作了。

  • 2020-12-21 14:00:19

    iframe + postMessage跨域通信

    在实际项目开发中可能会碰到在 a.com 页面中嵌套 b.com 页面,这时第一反应是使用 iframe,但是产品又提出在 a.com 中操作,b.com 中进行显示,或者相反。

  • 2020-12-22 12:02:41

    ios开发优秀的开源框架,demo集合

    期待大家和我们一起共同维护,同时也期望大家随时能提出宝贵的意见(直接提交issues即可)。请广大网友只按照目录结构(即使目录结构有问题)添加三方库,并提交pull request。目录问题大家提出issues后楼主会及时更改的。