• Save
Content URIs & URI Processing on Android
Upcoming SlideShare
Loading in...5
×
 

Content URIs & URI Processing on Android

on

  • 2,616 views

 

Statistics

Views

Total Views
2,616
Slideshare-icon Views on SlideShare
2,235
Embed Views
381

Actions

Likes
2
Downloads
0
Comments
0

25 Embeds 381

http://vkedco.blogspot.com 220
http://www.vkedco.blogspot.com 67
http://firety.com 32
http://vkedco.blogspot.in 13
http://vkedco.blogspot.de 10
http://www.vkedco.blogspot.in 6
http://vkedco.blogspot.co.uk 4
http://vkedco.blogspot.fr 4
http://vkedco.blogspot.com.au 3
http://vkedco.blogspot.com.es 3
http://vkedco.blogspot.fi 2
http://vkedco.blogspot.cz 2
http://vkedco.blogspot.ca 2
http://vkedco.blogspot.pt 2
http://vkedco.blogspot.ch 1
http://vkedco.blogspot.gr 1
http://vkedco.blogspot.com.br 1
http://www.vkedco.blogspot.co.il 1
http://www.vkedco.blogspot.nl 1
http://vkedco.blogspot.it 1
http://vkedco.blogspot.co.il 1
http://vkedco.blogspot.mx 1
http://vkedco.blogspot.nl 1
http://vkedco.blogspot.ro 1
http://vkedco.blogspot.kr 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Content URIs & URI Processing on Android Content URIs & URI Processing on Android Presentation Transcript

    • Content URIs & URI Processing on Android Vladimir Kulyukinhttp://www.youtube.com/vkedco www.vkedco.blogspot.com
    • Outline ● Content URIs ● URI Processing on Android – URI Elements – URI Matching Codes & Mimes – Matching URIshttp://www.youtube.com/vkedco http://www.vkedco.blogspot.com
    • Uniform Resource Indentifiershttp://www.youtube.com/vkedco http://www.vkedco.blogspot.com
    • Uniform Resource Identifier (URI) ● A URI is a string of characters that identifies a resource ● Uniform – means that different types of resource identifiers can be used in the same context even when their access mechanisms are different ● Resource – means anything that has an identity (e.g., a document, an image, a service) ● Identifier – means that it is a reference to a resource that with an identity (e.g., a sequence of characters with specific syntactic restrictions)http://www.youtube.com/vkedco http://www.vkedco.blogspot.com
    • Common Abbreviations: URI, URL, URN ● URL – Uniform Resource Locator ● URN – Uniform Resource Name ● Although the terms URI, URL, & URN are frequently used interchangeably, URL and URN are technically 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
    • 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
    • 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
    • Generic URI Syntax <scheme>://<authority><path>?<query>http://www.youtube.com/vkedco http://www.vkedco.blogspot.com
    • Example 01 in Color ● ftp://org.vkedco.mobappdev/resources/README.txt ● SCHEME: ftp ● AUTHORITY: org.vkedco.mobappdev ● PATH: /resources/README.txt ● PATH_SEGMENTS: /resources; README.txt ● PORT: -1 // it is not specified so defaults to -1 ● QUERY: null // not specified so defaults to nullhttp://www.youtube.com/vkedco http://www.vkedco.blogspot.com
    • 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 // not specified, defaults to -1 ● QUERY: null // not specified, defaults to nullhttp://www.youtube.com/vkedco http://www.vkedco.blogspot.com
    • 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
    • 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
    • Example 05 http://vkedco_content_server:8080/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
    • URI Processing & Design source code is herehttp://www.youtube.com/vkedco http://www.vkedco.blogspot.com
    • URI Access <scheme>://<authority><path>?<query> ● Uri.getScheme() ● Uri.getAuthority() ● Uri.getPath() ● Uri.getPathSegments() ● Uri.getPort() ● Uri.getQuery() ● Uri.getQueryParameter()http://www.youtube.com/vkedco http://www.vkedco.blogspot.com
    • 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
    • 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
    • URI Processing Steps ● Choose the scheme, e.g., content, http, etc. ● Design an authority ● Design MIMEs (Multipurpose Internet Mail Extensions) or use existing ones ● Design match codes to manage uri matching ● Use UriMatcher objects to add and match URIshttp://www.youtube.com/vkedco http://www.vkedco.blogspot.com
    • Sample Problem Suppose we want to create a resource that allows its clients to retrieve books, book titles, and book authors. What URIs do we need to support this resource?http://www.youtube.com/vkedco http://www.vkedco.blogspot.com
    • URIs: Scheme, Authority, Paths ● Scheme: content ● Authority: org.vkedco.mobappdev.content_providers.books ● Paths: – book_title/id // retrieve all book ids – book_title/id/# // retreive a specific book title id // (e.g., book_title/ids/1, book_title/ids/2, etc) – book_author/author // retrieve all authors – book_author/author/# // retrieve a specific book author whos // id is # – book_cover_image/cover_image // retrieve all images – book_cover_image/cover_image/# // retrieve a specific imagehttp://www.youtube.com/vkedco http://www.vkedco.blogspot.com
    • URIs: Matching Codes ● BOOK_ID_ALL = 0 ● BOOK_ID_SIGNLE = 1 ● BOOK_TITLE_ALL = 2 ● BOOK_TITLE_SINGLE = 3 ● BOOK_AUTHOR_ALL = 4 ● BOOK_AUTHOR_SINGLE = 5 ● BOOK_COVER_IMAGE_ALL = 6 ● BOOK_COVER_IMAGE_SINGLE = 7http://www.youtube.com/vkedco http://www.vkedco.blogspot.com
    • Adding URIs to UriMatcher static final String AUTHORITY = "org.vkedco.content_providers.books"; UriMatcher mUriMatcher = new UriMatcher(UriMatcher.NO_MATCH); static final String BOOK_ID_PATH = “/books/id/”; static final int CODE_BOOK_ID_ALL = 0; mUriMatcher.addURI(AUTHORITY, BOOK_ID_PATH, BOOK_ID_ALL);http://www.youtube.com/vkedco http://www.vkedco.blogspot.com
    • Adding URIs to UriMatcher static final String AUTHORITY = "org.vkedco.mobappdev.content_providers.books"; UriMatcher mUriMatcher = new UriMatcher(UriMatcher.NO_MATCH); static final String BOOK_ID_PATH = “/books/id/”; static final int CODE_BOOK_ID_ALL = 0; mUriMatcher.addURI(AUTHORITY, BOOK_ID_PATH, BOOK_ID_ALL); static final int CODE_BOOK_ID_SINGLE = 1; // uri matching code names 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
    • URI Matching Codes and Mimes // 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"; public String getType (Uri uri) { switch ( mUriMatcher.match(uri) ) { case BOOK_ID_SINGLE: return BOOK_TITLE_ID_SINGLE_MIME; case BOOK_ID_ALL: return BOOK_TITLE_ID_ALL_MIME; // etc }http://www.youtube.com/vkedco http://www.vkedco.blogspot.com
    • Basic URI Matching Pattern 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
    • 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
    • Feedback Bugs to vladimir dot kulyukin at gmail dot comhttp://www.youtube.com/vkedco http://www.vkedco.blogspot.com