UriMatcher 返回错误的值
我有两个尤里斯。假设它们是:
content://myprovider/messages
content://myprovider/messages/#
在我的扩展 ContentProvider 中,我声明了以下内容:
private static final int MESSAGES = 1;
private static final int MESSAGES_ID = 2;
private static final UriMatcher sUriMatcher;
static {
sUriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
sUriMatcher.addURI("myprovider", "messages", MESSAGES);
sUriMatcher.addURI("myprovider", "messages/#", MESSAGES_ID);
}
当我使用...
content://myprovider/messages/#
...Uri 调用任何 ContentProvider 方法(例如插入)时,我的 ContentProvider 方法会执行...
sUriMatcher.match(uri)
...然后我返回1(消息)。
为什么???
I have two Uris. Suppose they are:
content://myprovider/messages
content://myprovider/messages/#
In my extended ContentProvider I have declared the following:
private static final int MESSAGES = 1;
private static final int MESSAGES_ID = 2;
private static final UriMatcher sUriMatcher;
static {
sUriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
sUriMatcher.addURI("myprovider", "messages", MESSAGES);
sUriMatcher.addURI("myprovider", "messages/#", MESSAGES_ID);
}
When I use the...
content://myprovider/messages/#
...Uri when calling any ContentProvider method, say insert, and my ContentProvider method does a...
sUriMatcher.match(uri)
...and I get back 1 (MESSAGES).
Why???
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想获取
MESSAGES_ID
,则必须将 uri 编写为content://myprovider/messages/12345
,或者您必须为MESSAGES_ID< 添加模式/代码> 就像:
If you want to get
MESSAGES_ID
, the uri has to be written likecontent://myprovider/messages/12345
or you have to add a pattern forMESSAGES_ID
like: