public class AccessContentProiderTest extends AndroidTestCase { public void testInsert() throws Throwable{ ContentResolver resolver = getContext().getContentResolver(); Uri uri = Uri.parse("content://cn.test.providers.personprovider/person"); ContentValues values = new ContentValues(); values.put("name", "lili"); values.put("phone", "110"); values.put("amount", "3000000000"); resolver.insert(uri, values); } public void testDelete() throws Throwable{ ContentResolver resolver = getContext().getContentResolver(); Uri uri = Uri.parse("content://cn.test.providers.personprovider/person"); int num =resolver.delete(uri, null, null); } public void testUpdate() throws Throwable{ ContentResolver resolver = getContext().getContentResolver(); Uri uri = Uri.parse("content://cn.test.providers.personprovider/person/65"); ContentValues values = new ContentValues(); values.put("amount", 500); resolver.update(uri, values, null, null); } public void testQuery() throws Throwable{ ContentResolver resolver = getContext().getContentResolver(); Uri uri = Uri.parse("content://cn.test.providers.personprovider/person/65"); Cursor cursor = resolver.query(uri, null, null, null, "personid asc"); while(cursor.moveToNext()){ String name = cursor.getString(cursor.getColumnIndex("name")); Log.i("AccessContentProviderTest", name); } } }
Android使用内容提供者方式进行存储(2)
内容版权声明:除非注明,否则皆为本站原创文章。