FileDocCategorySizeDatePackage
ContentUris.javaAPI DocAndroid 5.1 API3758Thu Mar 12 22:22:10 GMT 2015android.content

ContentUris

public class ContentUris extends Object
Utility methods useful for working with {@link android.net.Uri} objects that use the "content" (content://) scheme. *

Content URIs have the syntax *

*

content://authority/path/id *

*
content:
The scheme portion of the URI. This is always set to {@link android.content.ContentResolver#SCHEME_CONTENT ContentResolver.SCHEME_CONTENT} (value content://).
authority
A string that identifies the entire content provider. All the content URIs for the provider start with this string. To guarantee a unique authority, providers should consider using an authority that is the same as the provider class' package identifier.
path
Zero or more segments, separated by a forward slash (/), that identify some subset of the provider's data. Most providers use the path part to identify individual tables. Individual segments in the path are often called "directories" although they do not refer to file directories. The right-most segment in a path is often called a "twig"
id
A unique numeric identifier for a single row in the subset of data identified by the preceding path part. Most providers recognize content URIs that contain an id part and give them special handling. A table that contains a column named _ID often expects the id part to be a particular value for that column.
*

Fields Summary
Constructors Summary
Methods Summary
public static Uri.BuilderappendId(Uri.Builder builder, long id)
Appends the given ID to the end of the path.

param
builder to append the ID to
param
id to append
return
the given builder

        return builder.appendEncodedPath(String.valueOf(id));
    
public static longparseId(android.net.Uri contentUri)
Converts the last path segment to a long.

This supports a common convention for content URIs where an ID is stored in the last segment.

throws
UnsupportedOperationException if this isn't a hierarchical URI
throws
NumberFormatException if the last segment isn't a number
return
the long conversion of the last segment or -1 if the path is empty

        String last = contentUri.getLastPathSegment();
        return last == null ? -1 : Long.parseLong(last);
    
public static android.net.UriwithAppendedId(android.net.Uri contentUri, long id)
Appends the given ID to the end of the path.

param
contentUri to start with
param
id to append
return
a new URI with the given ID appended to the end of the path

        return appendId(contentUri.buildUpon(), id).build();