Notice
Recent Posts
Recent Comments
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
Archives
Today
Total
관리 메뉴

c

Uri, Uri.Builder 본문

Google/Android

Uri, Uri.Builder

iuChannel 2013. 10. 23. 18:29

Uri.Builder 사용하시는 분들이 별로 없으신 것 같아서 간단히 설명드립니다.


Uri = scheme://authority/path?query=value 


와 같은 형태입니다.


Uri.Builder 를 사용하시면 Uri 를 쉽게 만들어서 사용하실 수 있습니다.


예를 들어, 


https://gdata.youtube.com/feeds/api/users/abc/playlists?v=2&alt=jsonc


와 같은 URL 이 있다면 아래 코드와 같이 코딩하신 뒤, toString() 을 사용하시면 됩니다.


https://gdata.youtube.com/feeds/api/users/abc/playlists?v=2&alt=jsonc 


Uri.Builder ub=new Uri.Builder();

ub.scheme("https")

.authority("gdata.youtube.com")

.appendPath("feeds").appendPath("api").appendPath("users")

.appendPath("abc").appendPath("playlists")

.appendQueryParameter("v", "2").appendQueryParameter("alt""jsonc");


String url=ub.build().toString();


특히, QueryParameter 의 경우에는 자주 바뀌거나 추가될 수 있기 때문에 코드의 재사용성이 꽤 괜찮을 것 같습니다.