我正在尝试根据几个示例实现我自己的 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);
但在 Google 的“iosched”引用应用中,它使用 *
如下:
matcher.addURI(authority, "rooms", ROOMS);
matcher.addURI(authority, "rooms/*", ROOMS_ID);
matcher.addURI(authority, "rooms/*/sessions", ROOMS_ID_SESSIONS);
谁能解释这两种方法的区别?
最佳答案
引用官方文档:http://developer.android.com/reference/android/content/UriMatcher.html .
public void addURI (String authority, String path, int code)
在 API 级别 1 中添加 添加一个要匹配的URI,以及匹配到这个URI时返回的代码。 URI节点可以是完全匹配的字符串,也可以是匹配任意文本的token“*”,也可以是只匹配数字的token“#”。
关于android - UriMatcher Uri *和#区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29430737/