我建议您熟悉以下文档:
内容提供者:
http://developer.android.com/guide/topics/providers/content-providers.html
基本上当您将该“URL”传递给 ContentResolver 时(大概您正在做这样的事情):
// Queries the user dictionary and returns results
mCursor = getContentResolver().query(
UserDictionary.Words.CONTENT_URI, // The content URI of the words table
mProjection, // The columns to return for each row
mSelectionClause // Selection criteria
mSelectionArgs, // Selection criteria
mSortOrder); // The sort order for the returned rows
您要求 android 将该 URL 解析为设置为处理该 URL 的 ContentProvider。 URL 不是“虚构的”,因为它的目标是本地对象和进程,这些对象和进程存在并由应用程序定义,这些应用程序使用 ContentProvider 机制来存储数据并使数据可供其他应用程序使用。
该 URL(在本例中被转换为 URI)的目标是指定您想要的 ContentProvider 以及您想要从中获得什么。
ContentProviders 通常由希望管理数据库并将该信息提供给其他应用程序同时最小化访问冲突等的应用程序使用。
编辑:
此代码来自您的教程。查看添加的 cmets:
/// this url points to the content provider.
//The content provider uses it to
///reference a specific database which it has knowledge of
//This URI doesn't represent an
//actual FILE on your system, rather it represents a way for you to tell the content //provider what DATABASE to access and what you want from it.
String URL = "content://com.example.provider.College/students";
// This line converts yoru "URL" into a URI
Uri students = Uri.parse(URL);
/// This call returns a Cursor - a cursor is a object type which contains the results of your QUERY in an order manner. IN this case it is a set of rows, each of which has a number of columns coresponding to your query and database, which can be iterated over to pull information from the DB..
/// managedQuery takes, as an argument, the URI conversion of the URL - this is
// where you are actually calling to the contentprovider, asking it to do a query on the
// databse for some information
Cursor c = managedQuery(students, null, null, null, "name");
// This line moves to the first ROW in the cursor
if (c.moveToFirst()) {
// this does somethign as long as the while loop conditional is true.
do{
// This line creates a pop up toast message with the information stored in the columns of the row you the cursor is currently on.
Toast.makeText(this,
c.getString(c.getColumnIndex(StudentsProvider._ID)) +
", " + c.getString(c.getColumnIndex( StudentsProvider.NAME)) +
", " + c.getString(c.getColumnIndex( StudentsProvider.GRADE)),
Toast.LENGTH_SHORT).show();
} while (c.moveToNext());
}
您在 cmets 中的问题是:
“我只需要这个文件的一个示例:String URL = "content://com.example.provider.College/students";,数据会是什么样子?”
这个问题的答案是,您的手机上某处有一个 Sqlite 数据库 - 通常(在这种情况下肯定是)由您正在访问的应用程序和/或内容提供商创建。您还知道内容解析器接受此 URI 和一些其他信息,并将返回一个 CURSOR。
这个问题解决了什么是光标。
use of cursor in android
如果你完整阅读教程,你会发现这段代码::
public class StudentsProvider extends ContentProvider {
static final String PROVIDER_NAME = "com.example.provider.College";
static final String URL = "content://" + PROVIDER_NAME + "/students";
static final Uri CONTENT_URI = Uri.parse(URL);
static final String _ID = "_id";
static final String NAME = "name";
static final String GRADE = "grade";
您还会在教程的清单中找到:
<provider android:name="StudentsProvider"
android:authorities="com.example.provider.College">
</provider>
您的 ContentProvider 对相关 URI 的注册是什么。
您会注意到您的 URL 与“PROVIDER_NAME”和“URL”有着惊人的相似之处。这是因为 ContentProvider 正在利用这些值来将自己标识为该部分 URI 到 android 系统的解析器。
您应该按照教程中的说明创建文件,制作示例应用程序功能,您将能够开始更清楚地理解这一点。