有没有真正的高手能解释清楚contentProvider的getType方法的作用是什么?不要挖baidu!我已经找过了!

解决方案 »

  1.   

    If you are handling a new data type, you must define a new MIME type to return in your implementation of ContentProvider.getType(). The type depends in part on whether or not the content: URI submitted to getType() limits the request to a specific record. There's one form of the MIME type for a single record and another for multiple records. Use the Uri methods to help determine what is being requested. Here is the general format for each type:For a single record:    vnd.android.cursor.item/vnd.yourcompanyname.contenttype
    For example, a request for train record 122, like this URI,
    content://com.example.transportationprovider/trains/122
    might return this MIME type:
    vnd.android.cursor.item/vnd.example.railFor multiple records:    vnd.android.cursor.dir/vnd.yourcompanyname.contenttype
    For example, a request for all train records, like the following URI,
    content://com.example.transportationprovider/trains
    might return this MIME type:
    vnd.android.cursor.dir/vnd.example.rail
      

  2.   

    感谢,但我还是没有太懂为什么contentprovider要返回mime字符串?
      

  3.   

    类似于标记的玩意嘛告诉你返回来的是什么类型的数据。。说不定有些provider存储了多种类型,比如文本啊,音乐啊,视频啊之类的。自己定义给自己用的provider,基本上用不着。
      

  4.   

    还是不太懂,,,
    返回的mime字符串用在哪里呢???
      

  5.   

    举个不那么恰当的例子。。有那么一个provider给你提供数据,然后你并不知道给你返回的是什么,因为他可能给你返回音乐,视频,或者图片。这时候你就用这个方法获得类型,再进行相应处理