Meaning of android.content.UriMatcher

前端 未结 3 1005
孤街浪徒
孤街浪徒 2021-02-19 01:08

What is Uri Matcher in android.content.UriMatcher

How to use it? Can someone please explain meaning of following three line of code?

  uriMa         


        
3条回答
  •  故里飘歌
    2021-02-19 01:42

    One more thing I wanted to add that wasn't clear for me first time I used UriMatcher.

    Is that if you want to parse an HTTP url then as an AUTHORITY parameter in the addURI you need to pass the target domain name. For example:

    Uri mUri = Uri.parse("http://example.com/foo");
    UriMatcher sURIMatcher = new UriMatcher(UriMatcher.NO_MATCH);
    
    // if not "example.com" below the match will always return -1 result
    sURIMatcher.addURI("example.com", "/foo", 123);
    
    int match = sURIMatcher.match(mUri);
    

    UriMatcher Documentation doesn't cover this case and it's not clear what's this authority parameter for. Gosh if I knew that it would save me some time!

提交回复
热议问题