Compartir a través de


ContentProvider.Canonicalize(Uri) Method

Definition

Implement this to support canonicalization of URIs that refer to your content provider.

[Android.Runtime.Register("canonicalize", "(Landroid/net/Uri;)Landroid/net/Uri;", "GetCanonicalize_Landroid_net_Uri_Handler")]
public virtual Android.Net.Uri? Canonicalize (Android.Net.Uri url);
[<Android.Runtime.Register("canonicalize", "(Landroid/net/Uri;)Landroid/net/Uri;", "GetCanonicalize_Landroid_net_Uri_Handler")>]
abstract member Canonicalize : Android.Net.Uri -> Android.Net.Uri
override this.Canonicalize : Android.Net.Uri -> Android.Net.Uri

Parameters

url
Uri

The Uri to canonicalize.

Returns

Uri

Return the canonical representation of <var>url</var>, or null if canonicalization of that Uri is not supported.

Attributes

Remarks

Implement this to support canonicalization of URIs that refer to your content provider. A canonical URI is one that can be transported across devices, backup/restore, and other contexts, and still be able to refer to the same data item. Typically this is implemented by adding query params to the URI allowing the content provider to verify that an incoming canonical URI references the same data as it was originally intended for and, if it doesn't, to find that data (if it exists) in the current environment.

For example, if the content provider holds people and a normal URI in it is created with a row index into that people database, the cananical representation may have an additional query param at the end which specifies the name of the person it is intended for. Later calls into the provider with that URI will look up the row of that URI's base index and, if it doesn't match or its entry's name doesn't match the name in the query param, perform a query on its database to find the correct row to operate on.

If you implement support for canonical URIs, <b>all</b> incoming calls with URIs (including this one) must perform this verification and recovery of any canonical URIs they receive. In addition, you must also implement #uncanonicalize to strip the canonicalization of any of these URIs.

The default implementation of this method returns null, indicating that canonical URIs are not supported.

Java documentation for android.content.ContentProvider.canonicalize(android.net.Uri).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to