什么是URI,contentValues [英] what are uri, contentValues
问题描述
谁能给我解释一下关于我已经使用在日历事件工作每学期?
-
乌里event_uri = Uri.parse(内容://com.android.calendar/+事件);
什么是URI这里,究竟是什么内容,我们可以初始化int值到0?它是
可以初始化一个URI具有缺省值? -
乌里reminder_uri = Uri.parse(内容://com.android.calendar/+提醒);
这意味着这些URI?之间有什么区别event_uri
和reminder_uri
? -
ContentValues值=新ContentValues();
values.put(CALENDAR_ID,1);
values.put(标题,STR);
values.put(说明,m_strDescription);
什么是第一个吗?values.put(CALENDAR_ID,1);
-
ContentResolver的CR = getContentResolver();
用的是什么内容解析器?有时候我们写的:开放的U = cr.insert(event_uri,价值观)
这是什么URI?它是如何从第一两个URI不同,例如event_uri
和reminder_uri
再次
values.put(事项标识,的Long.parseLong(event.getLastPathSegment())); cr.insert(remindar_uri,值);
这是什么做的?
对于问题1和问题2,A 乌里
是指向什么意义的地址。在的ContentProvider
S中的情况下,乌里
通常用来确定要使用的表。因此, event_uri
指向事件表和 reminder_uri
指向提醒表。实在是没有默认值的URI的。
对于问题3, ContentValues
实际上是一组键值对,其中键重新presents列的表和值是的要被插入在该列中的值。所以在 values.put的情况下(CALENDAR_ID,1);
,列是插入该列CALENDAR_ID和值是1。
对于问题4, ContentResolver的
是Android使用来解决乌里
s到 ContentProvider的
秒。任何人都可以创建一个的ContentProvider
和Android具有的ContentProvider
S为日历,联系人,等等。插入()
在 ContentResolver的
返回乌里
插入行的方法。因此,在问题1和问题2,那些乌里
取值指着表,但乌里
是分层的,使他们能够下定决心,特定行。例如:
内容://com.android.calendar/events
指向事件表,但
内容://com.android.calendar/events/1
指向事件表中的行ID为1
请记住,这是通常的行为,但提供了的ContentProvider
可以自定义的URI以不同的解决。
我会强烈建议阅读<一个在 ContentProvider的文档,尤其是部分href="http://developer.android.com/guide/topics/providers/content-provider-basics.html#ContentURIs">Content URI的。
从previously推荐文档:
在code中的previous线,完整的URI的单词表是:
内容:// user_dictionary /字
其中
user_dictionary
字符串 供应商的权力,而字
字符串表的路径。该 字符串内容://
(在计划)总是present,并确定该 作为内容的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?
Regarding questions 1 and 2, A Uri
is an address that points to something of significance. In the case of ContentProvider
s, the Uri
is usually used to determine which table to use. So event_uri
points to the events table and the reminder_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 of values.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 resolve Uri
s to ContentProvider
s. Anyone can create a ContentProvider
and Android has ContentProvider
s for the Calendar, Contacts, etc.. The insert()
method on a ContentResolver
returns the Uri
of the inserted row. So in questions 1 and 2, those Uri
s pointed to the table but Uri
s are hierarchical so they can resolve to a specific row. For example:
content://com.android.calendar/events
points to the events table, but
content://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:
In the previous lines of code, the full URI for the "words" table is:
content://user_dictionary/words
where the
user_dictionary
string is the provider's authority, andwords
string is the table's path. The stringcontent://
(the scheme) is always present, and identifies this as a content URI.
这篇关于什么是URI,contentValues的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!