• Like
  • Save
Mobile Application Development: Lecture 21
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

Mobile Application Development: Lecture 21

  • 444 views
Published

 

Published in Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
444
On SlideShare
0
From Embeds
0
Number of Embeds
9

Actions

Shares
Downloads
0
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Mobile Application Development Lecture 21 Vladimir Kulyukin Department of Computer Science Utah State Universityhttp://www.youtube.com/vkedco www.vkedco.blogspot.com
  • 2. Outline ● Content URIs ● URI Processing on Android – URI Elements – URI Matching Codes & Mimes – Matching URIshttp://www.youtube.com/vkedco http://www.vkedco.blogspot.com
  • 3. Uniform Resource Indentifiershttp://www.youtube.com/vkedco http://www.vkedco.blogspot.com
  • 4. Uniform Resource Identifier (URI) ● A URI is a string of characters that identifies an resource ● Uniform – different types of resource identifiers can be used in the same context even when their access mechanisms are different ● Resource – anything that has an identity (e.g., a document, an image, a service) ● Identifier – a reference to a resource that has an identity (e.g., a sequence of characters with specific syntactic restrictions)http://www.youtube.com/vkedco http://www.vkedco.blogspot.com
  • 5. URI, URL, URN ● URL – Uniform Resource Locator ● URN – Uniform Resource Name ● Although the terms URI, URL, and URN are frequently used interchangeably, URL and URN are subsets of URI ● URL is the subset of URIs that identify resources via their primary access mechanisms (http, ftp, gopher, etc) ● URN is the subset of URIs that are required to remain globally unique and persistent (even when the resources cease to exist)http://www.youtube.com/vkedco http://www.vkedco.blogspot.com
  • 6. URI Examples ● ftp://ftp.org.sample/rfc/rfc1001.txt ● gopher://univ.edu/classes/cs ● http://some_server:8080/public/home.html ● telnet://my_company.net/ ● mailto:user12345@gmail.com ● news:comp.infosystems.www.servers.unixhttp://www.youtube.com/vkedco http://www.vkedco.blogspot.com
  • 7. Hierarchical & Relative URIs ● Absolute URI refers to a resource regardless of the context in which it is used ● Relative URI refers to a resource within a specific namespace (e.g., absolute vs. relative file paths) ● Some URI schemes support hierarchical naming systems ● URI naming hierarchies use the “/” delimitershttp://www.youtube.com/vkedco http://www.vkedco.blogspot.com
  • 8. URI Design Criteria ● URI should be a sequence of characters and not always a sequence of octets (in CS, octet is a sequence of 8 bits, aka byte) ● URI may be transcribed from a non-network source and should consist of characters sensitive to constraints imposed by keyboards and locales ● URI should be remembered by people (should have meaningful components)http://www.youtube.com/vkedco http://www.vkedco.blogspot.com
  • 9. Generic URI Syntax <scheme>://<authority><path>?<query>http://www.youtube.com/vkedco http://www.vkedco.blogspot.com
  • 10. Example 01 ● ftp://org.vkedco.mobappdev/resources/hw10.txt ● SCHEME: ftp ● AUTHORITY: org.vkedco.mobappdev ● PATH: /resources/hw10.txt ● PATH_SEGMENTS: resources; hw10.xt ● PORT: -1 ● QUERY: nullhttp://www.youtube.com/vkedco http://www.vkedco.blogspot.com
  • 11. Example 02 content://org.vkedco.mobappdev.content_providers.books/book_title/id ● SCHEME: content ● AUTHORITY: org.vkedco.mobappdev.content_providers.books ● PATH: /book_title/id ● PATH_SEGMENTS: book_title; id ● PORT: -1 ● QUERY: nullhttp://www.youtube.com/vkedco http://www.vkedco.blogspot.com
  • 12. Example 03 content://org.vkedco.mobappdev.content_providers.books/book_title/id/10 ● SCHEME: content ● AUTHORITY: org.vkedco.mobappdev.content_providers.books ● PATH: /book_title/id/10 ● PATH_SEGMENTS: book_title; id ; 10 ● PORT: -1 ● QUERY: nullhttp://www.youtube.com/vkedco http://www.vkedco.blogspot.com
  • 13. Example 04 content://org.vkedco.mobappdev.content_providers.books/book_title?title=essential_rumi ● SCHEME: content ● AUTHORITY: org.vkedco.mobappdev.content_providers.books ● PATH: /book_title ● PATH_SEGMENTS: book_title ● PORT: -1 ● QUERY: title=essential_rumihttp://www.youtube.com/vkedco http://www.vkedco.blogspot.com
  • 14. Example 05 http:///vkedco_content_server:8080/book_title?book_title?title=essential_rumi&author=rumi ● SCHEME: http ● AUTHORITY: vkedco_content_server:8080 ● PATH: /book_title ● PATH_SEGMENTS: book_title ● PORT: 8080 ● QUERY: title=essential_rumi&author=rumihttp://www.youtube.com/vkedco http://www.vkedco.blogspot.com
  • 15. URI Processing on Androidhttp://www.youtube.com/vkedco http://www.vkedco.blogspot.com
  • 16. Getting URI Elements String getUriInfo(Uri uri) { StringBuilder sb = new StringBuilder(""); sb.append("URI: " + uri.toString() + "n"); sb.append("SCHEME: " + uri.getScheme() + "n"); sb.append("AUTHORITY: " + uri.getAuthority() + "n"); sb.append("PATH=" + uri.getPath() + "n"); sb.append("PATH SEGMENTS:n"); List<String> pathSegments = uri.getPathSegments(); for(int i = 0; i < pathSegments.size(); i++) { sb.append("path_sgmnt[" + i + "]=" + pathSegments.get(i) + "n"); } sb.append("PORT: " + uri.getPort() + "n"); sb.append("QUERY: " + uri.getQuery() + "n"); sb.append("TITLE_PARAM: " + uri.getQueryParameter("title") + "n"); sb.append("AUTHOR_PARAM: " + uri.getQueryParameter("author") + "n"); return sb.toString(); }http://www.youtube.com/vkedco http://www.vkedco.blogspot.com
  • 17. URI Matching Codes and Mimes static final String AUTHORITY = "org.vkedco.mobappdev.content_providers.books"; UriMatcher mUriMatcher; // uri matching codes static final int CODE_BOOK_ID_ALL = 0; static final int CODE_BOOK_ID_SINGLE = 1; // uri matching code names – for debugging only static final String CODE_BOOK_ID_ALL_NAME = "CODE_BOOK_ID_ALL"; static final String CODE_BOOK_ID_SINGLE_NAME = "CODE_BOOK_ID_SINGLE"; // uri mime types static final String BOOK_TITLE_ID_ALL_MIME = "vnd.android.cursor.dir/vnd.vkedco.mobappdev.book_id_all"; static final String BOOK_TITLE_ID_SINGLE_MIME = "vnd.android.cursor.item/vnd.vkedco.mobappdev.book_id_single";http://www.youtube.com/vkedco http://www.vkedco.blogspot.com
  • 18. Adding URIs UriMatcher // define paths static final String BOOK_ID_PATH = "book_title" + "/id"; static final String BOOK_TITLE_PATH = "book_title" + "/title"; static final String BOOK_AUTHOR_PATH = "book_author" + "/author"; static final String BOOK_COVER_PATH = "book_cover" + "/cover_image"; static final String SLASH_HASH = "/#"; mUriMatcher = new UriMatcher(UriMatcher.NO_MATCH); // content://org.vkedco.mobappdev.content_providers.books/book_title/id mUriMatcher.addURI(AUTHORITY, BOOK_ID_PATH, CODE_BOOK_ID_ALL); // content://org.vkedco.mobappdev.content_providers.books/book_title/id/# mUriMatcher.addURI(AUTHORITY, BOOK_ID_PATH + SLASH_HASH, CODE_BOOK_ID_SINGLE);http://www.youtube.com/vkedco http://www.vkedco.blogspot.com
  • 19. Matching URIs void matchUri(Uri uri) { int uri_match_code = mUriMatcher.match(uri); switch ( uri_match_code ) { case CODE_BOOK_ID_ALL: // do something with this URI break; case CODE_BOOK_ID_SINGLE: // do something with this URI break; // handle other cases }http://www.youtube.com/vkedco http://www.vkedco.blogspot.com
  • 20. UriTest Application Source code is herehttp://www.youtube.com/vkedco http://www.vkedco.blogspot.com
  • 21. References ● http://developer.android.com/guide/topics/providers/content-providers.html ● http://tools.ietf.org/html/rfc2046 ● http://www.iana.org/assignments/media-types ● http://www.faqs.org/rfcs/rfc2396.htmlhttp://www.youtube.com/vkedco www.vkedco.blogspot.com
  • 22. Feedback Bugs to vladimir dot kulyukin at gmail dot comhttp://www.youtube.com/vkedco http://www.vkedco.blogspot.com