Skip to content

Commit

Permalink
ContentProvider getType() Method
Browse files Browse the repository at this point in the history
  • Loading branch information
ujjwalmaity committed Jan 22, 2020
1 parent 6d07459 commit 6e9dae1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.net.Uri;
import android.provider.BaseColumns;
import android.content.ContentResolver;

public final class StudentContract {

Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

0 comments on commit 6e9dae1

Please sign in to comment.