标签:
内容提供者用于保存和检索数据,使android系统中不同应用程序之间可以进行共享数据.以uri的形式对外提供数据.
首先用一个类继承android.content包下contentprovide,重写一下方法.
1.public boolean oncreare() 创建contentprovide时调用.
2.public int delete(Uri uri, String selection, String[] selectionArgs) 删除指定数据.
3.public Uri insert(Uri uri, ContentValues values) 插入数据
4.public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) 更新指定条件下的数据
5.public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) 查询指定条件的数据
6.public String getType(Uri uri) 返回uri代表数据的MIME类型
其次写uri,由content://authorities/path
authorities指在清单文件中注册的android:authorities的值
path代表数据,动态改变
如:
private static UriMatcher matcher=new UriMatcher(UriMatcher.NO_MATCH); private static final int INSERT=1; private static final int DELETE=2; private static final int UPDATE=3; private static final int QUERY=4; private static final int QUERYONE=5; static { matcher.addURI("com.lss.readcontactmassage.PersonDBProvider","insert",INSERT); matcher.addURI("com.lss.readcontactmassage.PersonDBProvider","delete",DELETE); matcher.addURI("com.lss.readcontactmassage.PersonDBProvider","update",UPDATE); matcher.addURI("com.lss.readcontactmassage.PersonDBProvider","query",QUERY); //#为通配符,所有符合"query/"的都返回queryone的返回码 matcher.addURI("com.lss.readcontactmassage.PersonDBProvider","query/#",QUERYONE); }
public int match(Uri uri) 返回addUri方法中传入的参数的code值
标签:
原文地址:http://www.cnblogs.com/IT-lss/p/5664627.html