3.测试SQLite示例程序的ContentProvider
?????? ContentProvider即然是提供给其他应用访问本应用数据的,所以我们需要另创建一个Android应用,来测试SQLite示例程序的ContentProvider。我在此只列出query的测试方法testQuery:
public void testQuery() throws Throwable { ???????? ContentResolver contentResolver = this.getContext() ??????????????????????????? .getContentResolver(); ???????? Uri uri = Uri ??????????????????????????? .parse("content://com.changcheng.sqlite.provider/contact"); ???????? Cursor cursor = contentResolver.query(uri, new String[] { "_id", ??????????????????????????? "name", "phone" }, null, null, "_id desc"); ???????? while (cursor.moveToNext()) { ?????????????????? Log.i(TAG, "_id=" + cursor.getInt(0) + ",name=" ???????????????????????????????????? + cursor.getString(1) + ",phone=" + cursor.getString(2)); ???????? } } |
?
?????? 下一篇:Android数据存储之网络