一、在AndroidManifest.xml中加入:
<provider
android:name=".TalkHistoryProvider" android:authorities="com.g.im.talkhistoryprovider" />
二、自定义ContentProvider类:
<provider
android:name=".TalkHistoryProvider" android:authorities="com.g.im.talkhistoryprovider" />
二、自定义ContentProvider类:
public class TalkHistoryProvider extends ContentProvider {
private static UriMatcher mUriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
private static final int TALKHISTORYS = 1; // 集合类型
private static final int TALKHISTORY = 2; // 单个类型
private DBOpenHelper mDBOpenHelper;
static {
mUriMatcher.addURI("com.g.im.talkhistoryprovider", "talkhistory", TALKHISTORYS);
mUriMatcher.addURI("com.g.im.talkhistoryprovider", "talkhistory/#", TALKHISTORY);
}
@Override
public boolean onCreate() {
mDBOpenHelper = DBOpenHelper.getDBOpenHelper(this.getContext().getApplicationContext());
return true;
}
@Override
public String getType(Uri uri) {
switch (mUriMatcher.match(uri)) {
case TALKHISTORYS:
return "vnd.android.cursor.dir/talkhistory"; // 返回集合类型
case TALKHISTORY:
return "vnd.android.cursor.