什么是 uri、contentValues
谁能解释一下我在处理日历事件时使用的每个术语?
Uri event_uri = Uri.parse("content://com.android.calendar/" + "事件");
这里的 uri 是什么,实际上是什么内容,因为我们可以将 int 值初始化为 0?是吗
可以用默认值初始化 uri 吗?Uri Remember_uri = Uri.parse("content://com.android.calendar/" + "提醒");
这些uri代表什么?event_uri
和reminder_uri
之间有什么区别?ContentValues 值 = new ContentValues();
value.put("calendar_id", 1);
value.put("标题", str);
value.put("描述", m_strDescription);
第一个是做什么的?values.put("calendar_id", 1);
ContentResolver cr = getContentResolver();
内容解析器有什么用?有时我们会写:Uri u = cr.insert(event_uri, 值)
这个uri是什么?它与前两个 uri 有什么不同,例如event_uri
和reminder_uri
再次
values.put("event_id", Long.parseLong(event.getLastPathSegment())); cr.insert(remindar_uri, 值);
它有什么作用?
Can anyone explain me about each term that I have used in working with calendar events?
Uri event_uri = Uri.parse("content://com.android.calendar/" + "events");
What is uri here, what actually is content, as we can initialize int value to 0? Is it
possible to initialize a uri with a default value?Uri reminder_uri = Uri.parse("content://com.android.calendar/" + "reminders");
What signifies these uri? What are the differences betweenevent_uri
andreminder_uri
?ContentValues values = new ContentValues();
values.put("calendar_id", 1);
values.put("title", str);
values.put("description", m_strDescription);
What does the first one do?values.put("calendar_id", 1);
ContentResolver cr = getContentResolver();
What is the use of the content resolver? Sometimes we write:Uri u = cr.insert(event_uri, values)
What is this uri? How does it differ from the first two uris e.gevent_uri
andreminder_uri
Again
values.put("event_id", Long.parseLong(event.getLastPathSegment()));
cr.insert(remindar_uri, values);What does it do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
关于问题 1 和 2,
Uri
是一个指向重要内容的地址。对于ContentProvider
,Uri
通常用于确定要使用哪个表。因此,event_uri
指向事件表,reminder_uri
指向提醒表。 uris 实际上没有“默认值”。关于问题 3,ContentValues 本质上是一组键值对,其中键代表表的列,值是要插入到该列中的值。因此,在
values.put("calendar_id", 1);
的情况下,列是“calendar_id”,为该列插入的值为 1。关于问题 4,ContentResolver 是 android 用于将
Uri
解析为ContentProvider
的方法。任何人都可以创建ContentProvider
,并且 Android 具有用于日历、联系人等的ContentProvider
。上的
返回插入行的insert()
方法ContentResolverUri
。因此,在问题 1 和 2 中,这些Uri
指向表,但Uri
是分层的,因此它们可以解析为特定行。例如:content://com.android.calendar/events
指向事件表,但content://com.android.calendar/events/1
指向事件表中 id 为 1 的行。请记住,这是常见行为,但提供的
ContentProvider
可以自定义要以不同方式解析的 uri。我强烈建议阅读 ContentProvider 文档,特别是关于 内容 URI。
从之前推荐的文档来看:
Regarding questions 1 and 2, A
Uri
is an address that points to something of significance. In the case ofContentProvider
s, theUri
is usually used to determine which table to use. Soevent_uri
points to the events table and thereminder_uri
points to the reminders table. There is really no "default value" for uris.Regarding question 3, the
ContentValues
is essentially a set of key-value pairs, where the key represents the column for the table and the value is the value to be inserted in that column. So in the case ofvalues.put("calendar_id", 1);
, the column is "calendar_id" and the value being inserted for that column is 1.Regarding question 4, the
ContentResolver
is what android uses to resolveUri
s toContentProvider
s. Anyone can create aContentProvider
and Android hasContentProvider
s for the Calendar, Contacts, etc.. Theinsert()
method on aContentResolver
returns theUri
of the inserted row. So in questions 1 and 2, thoseUri
s pointed to the table butUri
s are hierarchical so they can resolve to a specific row. For example:content://com.android.calendar/events
points to the events table, butcontent://com.android.calendar/events/1
points to the row in the events table with id 1.Keep in mind, that this is the usual behavior, but the providing
ContentProvider
can customize the uris to be resolved differently.I would strongly recommend reading the ContentProvider docs, especially the section on Content URIs.
From the previously recommended documentation:
内容值:
ContentValues: