diff --git a/app/src/main/java/dev/ujjwal/sqlitedatastorage/data/StudentContract.java b/app/src/main/java/dev/ujjwal/sqlitedatastorage/data/StudentContract.java index 439da96..cde00a9 100644 --- a/app/src/main/java/dev/ujjwal/sqlitedatastorage/data/StudentContract.java +++ b/app/src/main/java/dev/ujjwal/sqlitedatastorage/data/StudentContract.java @@ -2,6 +2,7 @@ import android.net.Uri; import android.provider.BaseColumns; +import android.content.ContentResolver; public final class StudentContract { @@ -23,5 +24,14 @@ public static final class StudentEntry implements BaseColumns { public final static String COLUMN_BATCH = "batch"; public static final Uri CONTENT_URI = Uri.withAppendedPath(BASE_CONTENT_URI, PATH_STUDENTS); + + /** + * The MIME type of the {@link #CONTENT_URI} for a list of pets. + */ + public static final String CONTENT_LIST_TYPE = ContentResolver.CURSOR_DIR_BASE_TYPE + "/" + CONTENT_AUTHORITY + "/" + PATH_STUDENTS; + /** + * The MIME type of the {@link #CONTENT_URI} for a single pet. + */ + public static final String CONTENT_ITEM_TYPE = ContentResolver.CURSOR_ITEM_BASE_TYPE + "/" + CONTENT_AUTHORITY + "/" + PATH_STUDENTS; } } \ No newline at end of file diff --git a/app/src/main/java/dev/ujjwal/sqlitedatastorage/data/StudentProvider.java b/app/src/main/java/dev/ujjwal/sqlitedatastorage/data/StudentProvider.java index 8d1a79a..6db63db 100644 --- a/app/src/main/java/dev/ujjwal/sqlitedatastorage/data/StudentProvider.java +++ b/app/src/main/java/dev/ujjwal/sqlitedatastorage/data/StudentProvider.java @@ -172,6 +172,15 @@ public int delete(@NonNull Uri uri, @Nullable String selection, @Nullable String @Nullable @Override public String getType(@NonNull Uri uri) { - return null; + final int match = URI_MATCHER.match(uri); + + switch (match) { + case STUDENTS: + return StudentEntry.CONTENT_LIST_TYPE; + case STUDENTS_ID: + return StudentEntry.CONTENT_ITEM_TYPE; + default: + throw new IllegalStateException("Unknown URI " + uri + " with match " + match); + } } }