Problems with Android's UriMatcher

前端 未结 4 1176
你的背包
你的背包 2020-12-13 20:36

In an answer to a previous question of mine someone indicated that there is some flakiness (for lack of a better word) inherent in the Android class UriMatcher. Can anyone p

4条回答
  •  春和景丽
    2020-12-13 21:06

    Hum .... Ah typo ? Seems there is some whitespace after /reverse/

    uriMatcher.addURI(JobMetaData.AUTHORITY, "*/reverse/*", REVERSE_URI);
    

    should work

    EDIT

    The example below works, try with your values and check your LogCat Window for warnings

    Check the value in JobMetaData.AUTHORITY.

    public static final String PROVIDER ="org.dummy.provider" ;
    
    public static void doTest() 
    {
      testUri("content://"+PROVIDER +"/test/reverse/xb32") ; 
      testUri("content://"+PROVIDER +"/JobNames/YES/") ;
    }
    
    private static void testUri(String pStr) 
    {
        Uri uri = Uri.parse(pStr); 
        Log.w("Test", "uri = " + pStr) ;    
        int result = uriMatcher.match(uri) ;    
        Log.w("Test", "result = " + result) ;  
        List list = uri.getPathSegments() ;   
    
        for (int i = 0  ; i < list.size() ; i++)
          Log.w("Test", "Segment" + i + " = " + uri.getPathSegments().get(i)) ;   
    }
    

提交回复
热议问题