0

I am using UriMatcher and ContentProvider.

uriMatcher.addURI(DbContract.CONTENT_AUTHORITY, DbContract.PATH_CUSTOM_FIELDS + "/" + DbContract.PATH_DOMAIN + "/*", CUSTOM_FIELDS_DOMAIN);
uriMatcher.addURI(DbContract.CONTENT_AUTHORITY, DbContract.PATH_CUSTOM_FIELDS + "/" + DbContract.PATH_DOMAIN + "/" + DbContract.PATH_FORM + "/*/#", CUSTOM_FIELDS_DOMAIN_FORM);

All constants above are :-

DbContract.CONTENT_AUTHORITY = "com.ankiraw";

DbContract.PATH_CUSTOM_FIELDS = custom_fields
DbContract.PATH_DOMAIN = domain
DbContract.PATH_FORM = form
CUSTOM_FIELDS_DOMAIN_FORM = 100

I am passing uri

content://com.ankiraw/custom_fields/domain/form/ankiraw/38

to

uriMatcher.match(uri)

method as following :-

switch (uriMatcher.match(uri)) {

        case CUSTOM_FIELDS_DOMAIN_FORM:

            // some code here

            break;


        default:

            throw new IllegalArgumentException("Cannot query unknown URI " + uri); }

But it is not matching. Going to default case.

  • have look [UriMatcher](https://stackoverflow.com/a/26901852/5110595) – Hemant Parmar Jan 02 '18 at 05:04
  • For completeness post also you `DbContract.CONTENT_AUTHORITY`. – Enzokie Jan 02 '18 at 05:21
  • same code working for uris containing * only and # only. This particular uri is not working. –  Jan 02 '18 at 05:26
  • Your code looks fine to me, do you only have one matcher or you just did not include it in the question? – Enzokie Jan 02 '18 at 05:27
  • This is the only matcher, using many uris, this is the only uri which contains * and # both. –  Jan 02 '18 at 05:31
  • Actually the arrangement of your matcher can affect as well so you need to be careful which matcher will you add first and last. This [post](https://stackoverflow.com/a/15015687/5217712) shows the underlining algorithm behind URI matcher. – Enzokie Jan 02 '18 at 05:32
  • I got the answer. The matcher gets matched for first uri added by addURI that is for CUSTOM_FIELDS_DOMAIN constant. And just not going for the second uri check for constant CUSTOM_FIELDS_DOMAIN_FORM. The second uri pattern passed to matcher is matched for first added uri pattern. –  Jan 02 '18 at 06:04

0 Answers0