Search code examples
androiduriandroid-contentprovidermatcher

Uri Matcher doesn't match uri


Here is my Uri Matcher

static UriMatcher buildUriMatcher() {
    UriMatcher mUriMatcher = new UriMatcher(UriMatcher.NO_MATCH);

    // Bind uriMatcher int constants and uris
    mUriMatcher.addURI(OneSpaceContract.CONTENT_AUTHORITY, OneSpaceContract.PATH_DRIVE, DRIVE_LIST);
    mUriMatcher.addURI(OneSpaceContract.CONTENT_AUTHORITY, OneSpaceContract.PATH_DRIVE + "/#", DRIVE_ID);
    mUriMatcher.addURI(OneSpaceContract.CONTENT_AUTHORITY, OneSpaceContract.PATH_FILE, FILE_LIST);
    mUriMatcher.addURI(OneSpaceContract.CONTENT_AUTHORITY, OneSpaceContract.PATH_FILE + "/*", FILE_ID);
    mUriMatcher.addURI(OneSpaceContract.CONTENT_AUTHORITY, OneSpaceContract.PATH_FILE + "/drive/#", FILE_LIST_WITH_DRIVE_ID);
    mUriMatcher.addURI(OneSpaceContract.CONTENT_AUTHORITY, OneSpaceContract.PATH_FILE + "/file/*", FILE_LIST_WITH_FOLDER_ID);
    mUriMatcher.addURI(OneSpaceContract.CONTENT_AUTHORITY, OneSpaceContract.PATH_FILE + "/drive/#/*", FILE_LIST_WITH_DRIVE_ID_AND_FOLDER_ID);

    // Return the new matcher!
    return mUriMatcher;
}

Here is PATH_FILE constant

 public static final String PATH_FILE = "file";

UriMatcher doesn't match my uri

Uri : content://olexiimuraviov.ua.onespace_diplomaproject/file/drive/11/root

Here is an Exception

java.lang.UnsupportedOperationException: 
    Unknown uri: content://olexiimuraviov.ua.onespace_diplomaproject/file/drive/11/root
    at OneSpaceProvider.query(...)
     

I tried to debug and found nothing. Uri pattern looks fine and given uri is fine too, but matcher doesn't match it. Can you help me with this issue? Thanks in advance!


Solution

  • As Selvin stated on his example, the problematic rule is the one that binds FILE_ID. The first part of the segment matches, so it won't try to find any other rule that matches at that segment. Move that rule at the end and it should be fine.