1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
| public class PersonContentProvider extends ContentProvider {
private static final String AUTHORITY = "应用程序全包名";
private static final int PERSON_INSERT_CODE = 0; private static final int PERSON_DELETE_CODE = 1; private static final int PERSON_UPDATE_CODE = 2; private static final int PERSON_QUERY_ALL_CODE = 3;
private static UriMatcher uriMatcher;
private MySQLiteOpenHelper openHelper = new MySQLiteOpenHelper();
static {
uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
uriMatcher.addURI(AUTHORITY, "person/insert", PERSON_INSERT_CODE); uriMatcher.addURI(AUTHORITY, "person/delete", PERSON_DELETE_CODE); uriMatcher.addURI(AUTHORITY, "person/update", PERSON_UPDATE_CODE); uriMatcher.addURI(AUTHORITY, "person/queryAll", PERSON_QUERY_ALL_CODE); }
@Override public boolean onCreate() { return false; }
@Nullable @Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { return null; }
@Nullable @Override public String getType(Uri uri) { return null; }
@Nullable @Override public Uri insert(Uri uri, ContentValues values) { switch(uriMatcher.match(uri)) { case PERSON_INSERT_CODE: SQLiteDatabase db = openHelper.getWritableDatabase();
long id = db.insert("pserson", null, values);
return ContentUris.withAppendedId(uri, id); break; } return null; }
@Override public int delete(Uri uri, String selection, String[] selectionArgs) { return 0; }
@Override public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { return 0; } r
|