什么是URI,contentValues [英] what are uri, contentValues

查看:171
本文介绍了什么是URI,contentValues的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能给我解释一下关于我已经使用在日历事件工作每学期?

  1. 乌里event_uri = Uri.parse(内容://com.android.calendar/+事件);
    什么是URI这里,究竟是什么内容,我们可以初始化int值到0?它是
    可以初始化一个URI具有缺省值?

  2. 乌里reminder_uri = Uri.parse(内容://com.android.calendar/+提醒);
    这意味着这些URI?之间有什么区别 event_uri reminder_uri

  3. ContentValues​​值=新ContentValues​​();
    values​​.put(CALENDAR_ID,1);
    values​​.put(标题,STR);
    values​​.put(说明,m_strDescription);

    什么是第一个吗? values​​.put(CALENDAR_ID,1);

  4. 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?

  1. 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?

  2. Uri reminder_uri = Uri.parse("content://com.android.calendar/" + "reminders");
    What signifies these uri? What are the differences between event_uri and reminder_uri?

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

  4. 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.g event_uri and reminder_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 ContentProviders, 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 Uris to ContentProviders. Anyone can create a ContentProvider and Android has ContentProviders 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 Uris pointed to the table but Uris 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, and words string is the table's path. The string content:// (the scheme) is always present, and identifies this as a content URI.

这篇关于什么是URI,contentValues的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆