UriMatcher Uri * and # difference
Asked Answered
S

1

6

I'm trying to implement my own ContentProvider based on few examples but I'm confused by different approaches in UriMAtcher. For instance: JavaDoc shows it with #like this:

sURIMatcher.addURI("contacts", "people", PEOPLE);
sURIMatcher.addURI("contacts", "people/#", PEOPLE_ID);
sURIMatcher.addURI("contacts", "people/#/phones", PEOPLE_PHONES);
sURIMatcher.addURI("contacts", "people/#/phones/#", PEOPLE_PHONES_ID);

but in "iosched" reference app by Google it uses * like this:

matcher.addURI(authority, "rooms", ROOMS);
matcher.addURI(authority, "rooms/*", ROOMS_ID);
matcher.addURI(authority, "rooms/*/sessions", ROOMS_ID_SESSIONS);

Can anybody explain the difference of these two approaches ?

Scabby answered 3/4, 2015 at 10:48 Comment(2)
URI nodes may be exact match string, the token "*" that matches any text, or the token "#" that matches only numbers. Source: developer.android.com/reference/android/content/UriMatcher.htmlMordant
In case it helped you, kindly accept the answer. :)Mordant
M
10

Refer official docs : http://developer.android.com/reference/android/content/UriMatcher.html.

public void addURI (String authority, String path, int code)

Added in API level 1 Add a URI to match, and the code to return when this URI is matched. URI nodes may be exact match string, the token "*" that matches any text, or the token "#" that matches only numbers.

Mordant answered 3/4, 2015 at 11:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.