Uri学习总结

写在前面

写学习总结的目的就是尽量让各知识点简单明了的展现,节省再学习的时间成本。

结构格式:

1
2
[scheme]://[authority][path]?[query]#[fragment]
[authority] = [userinfo]@[host]:[port]

每个[]表示一个小模块可选可不选,通过了解了Uri的结构布局我们就可以任性的去解读不同的Uri了,因为万变不离其宗,所有的Uri都是按照这个结构来布局的。

样例:

1
2
3
4
5
6
7
8
9
10
Uri uri = Uri.parse("http://steven@www.java2s.com:8080/yourpath/fileName.htm?stove=10&path=32&id#pc");
uri.getScheme()->[scheme]->http
uri.getAuthority()->[userinfo]@[host]:[port]->steven@www.java2s.com:8080
uri.getSchemeSpecificPart()->//[userinfo]@[host]:[port][path]?[query]->//steven@www.java2s.com:8080/yourpath/fileName.htm?stove=10&path=32&id
uri.getUserInfo()->[userinfo]->steven
uri.getHost()->[host]->www.java2s.com
uri.getPort()->[port]->8080
uri.getPath()->[path]->/yourpath/fileName.htm
uri.getQuery()->[query]->stove=10&path=32&id
uri.getFragment()->[fragment]->pc

参考文章

Uri详解之——Uri结构与代码提取
Uri详解之二——通过自定义Uri外部启动APP与Notification启动