UriMatcher Uri *和#差异

时间:2015-04-03 10:48:42

标签: android uri android-contentprovider

我试图基于一些例子来实现我自己的ContentProvider,但我对UriMAtcher中的不同方法感到困惑。例如: JavaDoc#显示,如下所示:

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);

但在" iosched"谷歌的参考应用程序使用*,如下所示:

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

有人可以解释这两种方法的区别吗?

1 个答案:

答案 0 :(得分:9)

参考官方文档:http://developer.android.com/reference/android/content/UriMatcher.html

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

在API级别1中添加 添加要匹配的URI,以及匹配此URI时要返回的代码。 URI节点可以是完全匹配的字符串,令牌" *"匹配任何文本或令牌"#"只匹配数字。